Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'referring': 0.07; 'subject:question': 0.10; 'finish.': 0.16; 'received:74.208.4.195': 0.16; 'returncode': 0.16; 'wrote:': 0.18; 'command': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User- Agent:1': 0.23; 'case.': 0.24; 'script': 0.25; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'appreciated.': 0.29; 'am,': 0.29; 'code': 0.31; 'run': 0.32; 'url:python': 0.33; 'complete.': 0.36; 'url:org': 0.36; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'received:74.208': 0.68 Date: Mon, 08 Apr 2013 08:25:24 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: python-list@python.org Subject: Re: subprocess question re waiting References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:YoRWNCjykhccliEbtTbJIZVDvn/RcFm8SIUtfrx8QB5 dGChZRfg8cqZuxFSDOe0uk6iKNmmjMqkZSorQST7JoeZDW1n90 mkpDjpyR26Y5+I5pIBKpCgSD/K6vty90aQ1ee9eq41ErOOjyOz Si1O2z6hLU+nEEHHRgKhjT/TRMTHAJ8rAZ5oAL6BD996yOm+zj RgtfKEnuacbPs+868p7iWJgxPCehDWLeToWdKvh4cLIyYGF8Qv ZC6F18PNdwpAvO64WxyXwMFk0BuF5rkS66+zRHjEI9x4LeRrkT d5dcEkwYqSyU7Ioyh7dNIjP2OPK4hCpGSkqkY2g8rIgO0idTw= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365423943 news.xs4all.nl 6866 [2001:888:2000:d::a6]:48090 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43066 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