subprocess question re waiting

Dave Angel davea at davea.name
Mon Apr 8 08:25:24 EDT 2013


On 04/08/2013 07:00 AM, loial wrote:
> I want to call a child process to run a shell script and wait for that script to finish. Will the code below wait for the script to finish? If not then how do I make it wait?
>
> Any help appreciated.
>
>
> import subprocess
>
> command = "/home/john/myscript"
>
> process = subprocess.Popen(command, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True)
>
> out, err = process.communicate()
> returncode = process.returncode
>

Yes, communicate() will block until the child process is complete.

   http://docs.python.org/2/library/subprocess.html#popen-objects

Note the phrase:  "Wait for process to terminate."  That's referring to 
the shell in your case.

-- 
DaveA



More information about the Python-list mailing list