I would like to execute multiple commands within the command window I opened thru the subprocess.pOpen command ? how to do it ?
Something like
p = subprocess.Popen("start cmd /k ", stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=True )
now I want to call multiple commands in the same window I opened. I don't want to pass the argument as a list since it will only be treated as parameters of the first element in the list.
Following is the snippet which I keep it handy always to run windows commands.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.