[英]How to execute a command in a command window opened in Windows thru python subprocess.popen?
I would like to execute multiple commands within the command window I opened thru the subprocess.pOpen command ?我想在通过 subprocess.pOpen 命令打开的命令窗口中执行多个命令? 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.以下是我始终随身携带以运行 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.