我正在使用python的命令启动程序,但是执行命令后脚本会卡住,并且仅当我关闭打开的窗口时才会继续。所以,如果我这样做很简单:
import os
os.system('gedit')
print('aaaaaaaaaaaaa')
直到我关闭文本编辑器后才打印。subprocess.call
我已经编写了可以满足您需要的工作代码。
我已经在RedHat 7 Linux上对其进行了测试,并且可以正常工作。
代码:
import subprocess
proc = subprocess.Popen(["gedit"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
print("STDOUT: {0} \nSTDERR: {1}".format(stdout, stderr))
print("After I closed Gedit")
输出:
>>> python3 test.py
STDOUT: b''
STDERR: b'\n(gedit:683047): GVFS-RemoteVolumeMonitor-WARNING **: 08:20:31.346: remote volume monitor with dbus name org.gtk.vfs.GoaVolumeMonitor is not supported\n'
After I closed Gedit
注意:当然,Gedit已打开,当我关闭它时,程序运行继续。