我想通过subprocess.pOpen命令打开的命令窗口中执行多个命令?怎么做?
类似
p = subprocess.Popen("start cmd /k ", stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=True )
现在,我想在打开的同一窗口中调用多个命令。我不想将参数作为列表传递,因为它将仅被视为列表中第一个元素的参数。
下面是我总是方便地运行Windows命令的代码段。
import subprocess
result = []
win_cmd = 'ipconfig'
#shell=True means do not show the command shell
#shell=False means show the command shell
process = subprocess.Popen(win_cmd,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE )
for line in process.stdout:
print (line)
result.append(line)
errcode = process.returncode
for line in result:
print (line)