Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43066

Re: subprocess question re waiting

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 <davea@davea.name>
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 <davea@davea.name>
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 <ed0010ee-471d-4cbe-ae6c-1d9a172b2ffc@googlegroups.com>
In-Reply-To <ed0010ee-471d-4cbe-ae6c-1d9a172b2ffc@googlegroups.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.286.1365423942.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

subprocess question re waiting loial <jldunn2000@gmail.com> - 2013-04-08 04:00 -0700
  Re: subprocess question re waiting Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-04-08 13:48 +0200
    Re: subprocess question re waiting Dylan Evans <dylan@dje.me> - 2013-04-08 22:01 +1000
    Re: subprocess question re waiting Dave Angel <davea@davea.name> - 2013-04-08 08:22 -0400
    Re: subprocess question re waiting Dylan Evans <dylan@dje.me> - 2013-04-08 22:58 +1000
  Re: subprocess question re waiting Dave Angel <davea@davea.name> - 2013-04-08 08:25 -0400

csiph-web