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执行带有空格的路径比较方便

 

posted on 2020-10-26 11:43  sunny_2016  阅读(320)  评论(0编辑  收藏  举报

导航