繁体   English   中英

如何在 Windows 中通过 python subprocess.popen 打开的命令窗口中执行命令?

[英]How to execute a command in a command window opened in Windows thru python subprocess.popen?

我想在通过 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM