[英]Executing a program from python so that it opens in separate cmd.exe window
How can I execute a program from within python program so that it opens in a separate cmd.exe window with the output of the executed program? 如何在python程序中执行程序,以便在单独的cmd.exe窗口中打开该程序,并显示执行程序的输出? I tried using subprocess.popen but it doesn't display the cmd.exe window while the program is running.
我尝试使用subprocess.popen,但程序运行时它不显示cmd.exe窗口。
In Windows, you need to declare optional variable shell=True and use start: 在Windows中,您需要声明可选变量shell = True并使用start:
subprocess.Popen('start executable.exe', shell=True)
or if you want to kill the shell after running the executable: 或者,如果您想在运行可执行文件后杀死Shell:
subprocess.Popen('start cmd /C executable.exe', shell=True)
For example: 例如:
subprocess.Popen('start dir', shell=True)
subprocess.Popen('start cmd /C dir', shell=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.