在Python中使用os.system()是打开程序,看不到已启动程序的window
Using os.system() in Python is open a program, can't see window of launched program
我正在尝试从 python 代码中启动 program/GUI。
在终端中,我只需键入程序名称即可启动程序。几行输出到终端,然后一个单独的 window 打开 GUI。
我试图通过 运行
在 python 中模仿这一点
os.system("<program name>")
如上所述,典型的输出行被打印到控制台,但没有 window 使用 GUI 打开。
可以使用 os.system() 来执行具有独立 window 的程序吗?
这是一个使用subprocess
的解决方案
import subprocess
subprocess.Popen("notepad.exe")
或者,如果您想 运行 一个带有特定解释器的 python 程序:
subprocess.Popen('{0} {1}'.format(PythonInterpreterPath,PythonFilePath.py))
[os.system
] is implemented by calling the Standard C function
system()
也就是说,使用 os.system
启动 GUI 应用程序应该没有任何问题。我自己试了一下,效果很好。
手册中还提到:
The subprocess module provides more powerful facilities for spawning
new processes and retrieving their results; using that module is
preferable to using this function.
也许这值得一试。当您使用 os.system
?
生成任何其他 GUI 应用程序时,它们是否工作?
我正在尝试从 python 代码中启动 program/GUI。
在终端中,我只需键入程序名称即可启动程序。几行输出到终端,然后一个单独的 window 打开 GUI。
我试图通过 运行
在 python 中模仿这一点os.system("<program name>")
如上所述,典型的输出行被打印到控制台,但没有 window 使用 GUI 打开。
可以使用 os.system() 来执行具有独立 window 的程序吗?
这是一个使用subprocess
import subprocess
subprocess.Popen("notepad.exe")
或者,如果您想 运行 一个带有特定解释器的 python 程序:
subprocess.Popen('{0} {1}'.format(PythonInterpreterPath,PythonFilePath.py))
[
os.system
] is implemented by calling the Standard C functionsystem()
也就是说,使用 os.system
启动 GUI 应用程序应该没有任何问题。我自己试了一下,效果很好。
手册中还提到:
The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function.
也许这值得一试。当您使用 os.system
?