Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'output': 0.05; '"the': 0.07; 'alain': 0.09; 'exits': 0.09; 'received:209.85.219': 0.09; 'subject:question': 0.10; 'cc:addr :python-list': 0.11; 'command,': 0.16; 'finish.': 0.16; 'it."': 0.16; 'it."': 0.16; 'simplifies': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'users.': 0.18; 'bit': 0.19; '>>>': 0.22; 'code,': 0.22; 'email addr:gmail.com>': 0.22; 'manual': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'skip:l 30': 0.24; 'mon,': 0.24; 'non': 0.24; 'cc:2**0': 0.24; 'script': 0.25; 'handling': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'unix': 0.29; 'andrew': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; '>>>>': 0.31; 'writes:': 0.31; 'run': 0.32; 'url:python': 0.33; '"the': 0.34; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'received:209': 0.37; 'url:library': 0.38; 'pm,': 0.38; 'does': 0.39; 'url:mail': 0.40; 'how': 0.40; 'dave': 0.60; 'first': 0.61; 'nobody': 0.68; 'angel': 0.91; 'to:none': 0.92; '2013': 0.98 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:x-originating-ip:in-reply-to:references :date:message-id:subject:from:cc:content-type:x-gm-message-state; bh=L/5hQ4Sqb6KpCVIvuHSc2Qywpiy8cRr0MKJt8y9/Ma4=; b=YVdbf+lFDDZ4jX0my8N3/MzyyOpI74/rqD32BKSTI294MhBpgboQFm+xSuSuY5Frn/ cNo//I9x1jqVCYp1Z4Sy36vZOvO4Q3BSTzFHxxW7JV24hwbw9gH/1f1a95SWa+0FamuZ dLD8TrdWdebn/rJ/O6MY/PGFWA6dnyXLzaKQZLN1hMCe19g8b88Hp7hY68yq4rmnor11 8nkAUEecn+GV40QVCmybn3CXlJ3jDvMUfEbf96FFeXV9ACHL2dbrvQOHOrKycjXooMo3 M+tZwOtUsd/mZ2+UNiiL2Uj7Iv6adZwHSeGUb7Z9nL9OlJ5zgTgerhoFTe9TupqJa3nS VoSw== MIME-Version: 1.0 X-Received: by 10.182.117.131 with SMTP id ke3mr2822249obb.60.1365425900509; Mon, 08 Apr 2013 05:58:20 -0700 (PDT) X-Originating-IP: [220.245.216.139] In-Reply-To: <5162B69D.90908@davea.name> References: <8761zxdyzb.fsf@dpt-info.u-strasbg.fr> <5162B69D.90908@davea.name> Date: Mon, 8 Apr 2013 22:58:20 +1000 Subject: Re: subprocess question re waiting From: Dylan Evans Cc: python-list Content-Type: multipart/alternative; boundary=089e0149cbfac470ca04d9d8fdca X-Gm-Message-State: ALoCoQkPIWzaJ6G34C5NvtXMNBM7PzgW9E1T2ygdlVKnI3KwP1vsp/UhbnzxCzO6HlrNIvos0qGV 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: 148 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365425904 news.xs4all.nl 6890 [2001:888:2000:d::a6]:38426 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43069 --089e0149cbfac470ca04d9d8fdca Content-Type: text/plain; charset=ISO-8859-1 On Mon, Apr 8, 2013 at 10:22 PM, Dave Angel wrote: > On 04/08/2013 08:01 AM, Dylan Evans wrote: > >> On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin < >> alain@dpt-info.u-strasbg.fr >> >>> wrote: >>> >> >> loial writes: >>> >>> 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? >>>> >>> [...] >>> >>>> process = subprocess.Popen(command, >>>> >>> stdin=subprocess.PIPE,stdout=**subprocess.PIPE, stderr=subprocess.PIPE, >>> close_fds=True, shell=True) >>> >>> process.wait() >>> >>> >> Or use subprocess.call instead which does what you want. >> >> Actually after having a look through the manual i like check_output for this since it simplifies the code, but some extra exception handling would be required if the output is still required when the script exits with a non zero value, so it's a bit of a trade off. > -- Alain. >>> -- >>> http://mail.python.org/**mailman/listinfo/python-list >>> >>> >> > http://docs.python.org/2/**library/subprocess.html#popen-**objects > > or use communicate(), which is what the OP had in the first place. > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum --089e0149cbfac470ca04d9d8fdca Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Mon, Apr 8, 2013 at 10:22 PM, Dave Angel <<= a href=3D"mailto:davea@davea.name" target=3D"_blank">davea@davea.name&g= t; wrote:
On 04/08/2013 08:01 AM, Dy= lan Evans wrote:
On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin <alain@dpt-info.u-strasbg.fr
wrote:

loial <jldunn2= 000@gmail.com> writes:

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?
[...]
process =3D subprocess.Popen(command,
stdin=3Dsubprocess.PIPE,stdout=3Dsubprocess.PIPE, stderr=3Dsubproces= s.PIPE,
close_fds=3DTrue, shell=3DTrue)

process.wait()


Or use subprocess.call instead which does what you want.


Actually afte= r having a look through the manual i like check_output for this since it si= mplifies the code, but some extra exception handling would be required if t= he output is still required when the script exits with a non zero value, so= it's a bit of a trade off.
=A0
http://docs.python.org/2/library/subprocess.= html#popen-objects

or use communicate(), which is what the OP had in the first place.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list



--
"The UNIX system has a command, nice ... in order to be nice to= the other users. Nobody ever uses it." - Andrew S. Tanenbaum
--089e0149cbfac470ca04d9d8fdca--