   [Python] Wait for a child process created with P_DETACH
import osargs=['c:\\windows\\system32\\ping.exe', 'www.google.com']pid = os.spawnv(os.P_DETACH, args[0], args)# Do stuff in parallel.os.waitpid(pid) # Error, pid == 0What I'm trying here is to start a child process without polluting the ouput console of the current process. In this example, the child process is actually started (I can see 'ping.exe' in the task manager) but the problem is I don't know how to get the correct pid.Python's doc states that "P_DETACH is similar to P_NOWAIT, but the new process is detached from the console of the calling process"If I use 'os.P_NOWAIT' instead, I get the expected behavior but the child process completely messes up my output, which I'd like to avoid.Btw, my OS is Windows XP.Any ideas?   
  I fiddled around with it and I couldn't get os.waitpid() to work properly either. Anyway, the os.spawn* functions are considered...maybe not 'obsolete', but I guess I would say 'too low level' for everyday use. It is preferred to use the subprocess module. I'll give you an example, but read the subprocess docs to find a way that best fits your needs.import subprocessdef test():    print "Starting process..."    proc = subprocess.Popen(['C:\\Windows\\system32\\ping.exe', 'www.google.com'], stdout=subprocess.PIPE)    pipe = proc.stdout    print "Waiting for process..."    r = proc.wait()    print "Process finished. Return code is", r    print "Contents of pipe:"    for line in pipe:   print line    pipe.close() [Edited by - Hollower on March 10, 2008 11:17:58 PM];  That's what I needed. thanksI had taken a look at subprocess's doc but I found it pretty incomplete (almost like work in progress) I may have looked at the wrong place, I guess...   