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

如何通过python subprocess.popen在Windows中打开的命令窗口中执行命令?,python,subprocess,popen,Python,Subprocess,Popen,我想在通过subprocess.pOpen命令打开的命令窗口中执行多个命令?怎么做 差不多 p = subprocess.Popen("start cmd /k ", stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=True ) 现在,我想在打开的同一个窗口中调用多个命令。 我不想将参数作为列表传递,因为它只会被视为列表中第一个元素的参数 下面是一个代码片段,我总是把它放在运行windows命令的地方 import subprocess

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

为什么不创建一个批处理文件并调用该批处理文件?或者您是否需要该命令提示符和该python程序之间的任何交互请检查此链接-如果您需要交互或一个接一个地发送命令,Dinesh建议的任何内容都很好,我想根据我进入窗口的消息发出命令。因此,提前运行批处理文件对我来说不是一个解决方案。。