1
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.

Eby
  • 43
  • 1
  • 6
  • See https://stackoverflow.com/questions/24694763/how-to-let-the-child-process-live-when-parent-process-exited – Rocco Fortuna Nov 27 '21 at 13:14
  • @Rocco I tried `os._exit(0)` instead of `sys.exit()` but it did not work. Actually, child.exe went to be an unresponsive state as soon as it started running. – Eby Nov 27 '21 at 13:55

1 Answers1

0

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.

Eby
  • 43
  • 1
  • 6