python下执行CMD命令的不同方法

import os
import subprocess

#import sys
os.system('echo the first command&&echo the second command')#强制执行,无法获取返回结果
os.popen('cd C:\Users\XXX\AppData\Local\Google\Chrome\Application\ & chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\selenium_ui_auto\chrome_temp"') #1.win7下可能失败,win10下正常 可以转换为绝对路径执行,如下面 2.可以获取返回结果
subprocess.run('C:\Users\XXX\AppData\Local\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\selenium_ui_auto\chrome_temp"')
#subprocess.run执行带有空格的路径比较方便
原文地址:https://www.cnblogs.com/51testing/p/13877672.html