import sys, subprocess, os
path = 'child.exe path'
args = [path]
subprocess.Popen(args, creationflags=subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP)
sys.exit()
I ran this script, child.exe died with script. It didn't even look like it was executed. Is it possible to keep the child.exe alive after the script dies? I am using Python 3.9.7.
I found a way might not good but worked.
subprocess.run(args) # not popen not shell=true
sys.exit()
subprocess.run()
blocks the thread until end of child process, in that while, child process kills the parent process. It did not worked if I set shell=True
for subprocess.run()
. Please let me know if you have a good way. This was tested on windows 10, python 397.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.