Python运行系统命令,然后退出...不会退出 [英] Python run system command and then exit... won't exit

查看:135
本文介绍了Python运行系统命令,然后退出...不会退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下python代码:

I have the following python code:

os.system("C:/Python27/python.exe C:/GUI/TestGUI.py")
sys.exit(0)

它运行得很好,并弹出一个窗口.但是,它不会退出第一个脚本.它只是停留在那儿,我最终不得不强行终止进程.没有错误产生.发生了什么事?

It runs the command fine, and a window pops up. However, it doesn't exit the first script. It just stays there, and I eventually have to force kill the process. No errors are produced. What's going on?

推荐答案

而不是os.system使用subprocess.Popen

这会运行一个命令,而不等待它,然后退出:

this runs a command and doesn't wait for it and then exits:

import subprocess
import sys

subprocess.Popen(["mupdf", "/home/dan/Desktop/Sieve-JFP.pdf"])
sys.exit(0)

请注意os.system(command)喜欢:

p = subprocess.Popen(command)
p.wait()

这篇关于Python运行系统命令,然后退出...不会退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆