从python执行一个程序,使其在单独的cmd.exe窗口中打开

时间:2013-12-09 12:22:57

标签: python cmd subprocess

如何在python程序中执行程序,以便在单独的cmd.exe窗口中打开,并显示已执行程序的输出? 我尝试使用subprocess.popen,但在程序运行时它没有显示cmd.exe窗口。

1 个答案:

答案 0 :(得分:6)

在Windows中,您需要声明可选变量shell = True并使用start:

subprocess.Popen('start executable.exe', shell=True)

或者如果要在运行可执行文件后终止shell:

subprocess.Popen('start cmd /C executable.exe', shell=True)

例如:

subprocess.Popen('start dir', shell=True)

subprocess.Popen('start cmd /C dir', shell=True)
相关问题