Sun*_*y88 1 python subprocess cmd
如何从python程序中执行一个程序,以便它在一个单独的cmd.exe窗口中打开,并显示已执行程序的输出?我尝试使用subprocess.popen但它在程序运行时不显示cmd.exe窗口.
在Windows中,您需要声明可选变量shell = True并使用start:
subprocess.Popen('start executable.exe', shell=True)
Run Code Online (Sandbox Code Playgroud)
或者如果要在运行可执行文件后终止shell:
subprocess.Popen('start cmd /C executable.exe', shell=True)
Run Code Online (Sandbox Code Playgroud)
例如:
subprocess.Popen('start dir', shell=True)
subprocess.Popen('start cmd /C dir', shell=True)
Run Code Online (Sandbox Code Playgroud)