Python run system command and then exit… won't exit

前端 未结 4 924
悲&欢浪女
悲&欢浪女 2021-02-04 13:02

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 po

4条回答
  •  耶瑟儿~
    2021-02-04 13:47

    instead of os.system use 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)
    

    note that os.system(command) like:

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

提交回复
热议问题