1

Using python 2.7, windows 7 64 bit. I want to call external application to get launch using python script. And after launching external application, the main process should continue and finally terminate without ever waiting or listening for external application to terminate. Means, as external application is launched, main process should not depend on external application for termination. I used:

print "ss"
os.system(r"D:\pythonCode\external.exe")
print "application started"

In above,code, external.exe is launched, but it never prints "application started", and main process so never terminates.

Also tried with:

p = subprocess.Popen([r"D:\pythonCode\external.exe"])
print "application started"
sys.exit(0)

In above case, external.exe is launched, it prints "application started", but main process never terminates. Main process waits for external application to terminates, which is not desired. I also looked into this q&a but not get solution for it.

I also tried with p=subprocess.Popen([r"D:\pythonCode\external.exe"],creationflags=subprocess.CREATE_NEW_PROCESS_GROUP), but same blocking happens

and also

DETACHED_PROCESS = 0x00000008
pid = subprocess.Popen([r"D:\pythonCode\external.exe"], creationflags=DETACHED_PROCESS).pid
Community
  • 1
  • 1
imp
  • 1,967
  • 2
  • 28
  • 40
  • duplicated! http://stackoverflow.com/a/16928558/1093020 – Leonardo.Z Mar 13 '14 at 07:20
  • @Leonardo.Z The answer is for unix system, I am asking for windows HERE – imp Mar 13 '14 at 07:29
  • read the answer again! – Leonardo.Z Mar 13 '14 at 07:30
  • @Leonardo.Z preexec_fn=os.setpgrp is nor unix, can you comment here the answer you are talking about – imp Mar 13 '14 at 07:42
  • preexec_fn is for un*x-oids only. There appears to be a rough equivalent for Windows "creationflags=CREATE_NEW_PROCESS_GROUP", but I've never tried it.) – Leonardo.Z Mar 13 '14 at 08:45
  • @Leonardo.Z please see the latest edit question. I tried p=subprocess.Popen([r"D:\pythonCode\external.exe"],creationflags=subprocess.CREATE_NEW_PROCESS_GROUP), but that also is blocking – imp Mar 13 '14 at 09:19
  • 1
    try `os.startfile()`. Or [`start_new_session` analog](http://stackoverflow.com/a/13256908/4279) – jfs Mar 13 '14 at 11:57

0 Answers0