On Sat, 07 Sep 2013 03:55:02 -0700, larry.mart...@gmail.com wrote: > I have a python script and when I run it directly from the command line > it runs to completion. But I need to run it from another script. I do > that like this: > > p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) > rv = p.wait() > out_buf = p.stdout.read() > > When I do this, wait never returns.
The last two statements are the wrong way around. If you're reading a process' output via a pipe, you shouldn't wait() for it until it has closed its end of the pipe. As it stands, you have a potential deadlock. If the subprocess tries to write more data than will fit into the pipe, it will block until the parent reads from the pipe. But the parent won't read from the pipe until after the subprocess has terminated, which won't happen because the subprocess is blocked waiting for the parent to read from the pipe ... -- https://mail.python.org/mailman/listinfo/python-list