如何从 python 程序中执行程序,以便它在单独的 cmd.exe 窗口中打开并显示已执行程序的输出? 我尝试使用 subprocess.popen 但它在程序运行时不显示 cmd.exe 窗口。
请您参考如下方法:
在 Windows 中,您需要声明可选变量 shell=True 并使用启动:
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)
