I’m trying to simulate behavior of os.system with Popen and waitpid on Ubuntu and I’m getting
OSError: [Errno 10] No child processes
here’s how I’m using it
p = Popen(args, stdout = PIPE, stderr = PIPE)
stdout, stderr = p.communicate()
returncode = os.waitpid(p.pid, 0)[1]
I tried to get return code out of p.returncode , but it is always None, any ideas how to get the return code?
communicatealready waits on the child process to terminate, and collects the return code itself. Therefore, when you callos.waitpid, you’re calling it referencing a process ID that has already been removed from the OS tables. Therefore, you get the “No child process” error.The return code you’re looking for will be stored in the returncode field of of the process object after
communicatereturns.