使用"subprocess.Popen()"打开的应用程序如何终止?

5

我希望在 GNOME 图像查看器 (eog) 中查看一张图片,并且希望它稍后自动关闭。 我对 subprocess 不是很熟悉,但是迄今为止我尝试了以下方法:

eog = subprocess.Popen('oeg <some file>', shell=True)
# ...Code, Code, Code...
eog.kill()

或者

eog.terminate()

两者都不起作用。有什么帮助吗?

请发布更多的代码,并说明您如何检查进程是否被终止。 - BrainStorm
它们在我的电脑上都能工作?! - Emil Ivanov
1个回答

4
不要使用 shell=True,例如:
import subprocess, shlex
command = 'eog <filename'>
eog = subprocess.Popen(shlex(command))
..code..
eog.kill()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接