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


Groups > comp.lang.python > #52814

Re: Running a command line program and reading the result as it runs

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'returned.': 0.07; 'tries': 0.07; '22,': 0.09; 'parameter': 0.09; 'subject:command': 0.09; '3:51': 0.16; 'blocks': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:program': 0.16; 'wrote:': 0.18; 'producing': 0.19; 'thu,': 0.19; 'work,': 0.20; 'command': 0.22; 'aug': 0.22; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'lines': 0.31; 'fine,': 0.31; 'anyone': 0.31; 'run': 0.32; 'worked': 0.33; 'subject:the': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'ian': 0.60; 'soon': 0.63; 'between': 0.67; 'results': 0.69; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=aDge9LmG4yvoR6onsxXcF0+AH6k56/WjQZRlnliiYC8=; b=la+Lcw4ZQvcw06dDkodWDD/CY3lYbC3Exg/W+o5ahn0PDdclEHw3ok3N8sfnmGy4A/ X/EsKM/tnPcUlu6MIq2fv0+tiaLt1y/03OyXN/d6/iQJokF58Q2YZmRaZsy27l1+w4e4 0V0pxirwlJ6PNg+T6WzVACFT1XSkN6iWtB5omKwOLs3F83JVM9l252Z5hFGXry4kwMTG njeN+I9wq7Z6fl9ACVPY3TH0UVbhGg+NQOsIDGOr+DqTRhEjhhInmFEvymwdgheCDtuZ 7+rGrcUShfNdZzi3tb0Z+m+pIKwy9IiKq+q+/oA20WIwY0jbYzlVdIvhSBvyTTR64Ewf cNWg==
MIME-Version 1.0
X-Received by 10.221.47.193 with SMTP id ut1mr9935226vcb.8.1377152539851; Wed, 21 Aug 2013 23:22:19 -0700 (PDT)
In-Reply-To <5215a6cf$0$6512$c3e8da3$5496439d@news.astraweb.com>
References <5215a6cf$0$6512$c3e8da3$5496439d@news.astraweb.com>
Date Thu, 22 Aug 2013 16:22:19 +1000
Subject Re: Running a command line program and reading the result as it runs
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.119.1377152952.19984.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377152952 news.xs4all.nl 15908 [2001:888:2000:d::a6]:39753
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52814

Show key headers only | View raw


On Thu, Aug 22, 2013 at 3:51 PM, Ian Simcock
<Ian.Simcock@internode.on.net> wrote:
> When I use this code I can see that the Popen works, any code between the
> Popen and the for will run straight away, but as soon as it gets to the for
> and tries to read p.stdout the code blocks until the command line program
> completes, then all of the lines are returned.
>
> Does anyone know how to get the results of the program without it blocking?

Is the program actually producing output progressively? I just tried
your exact code with "dir /ad /s /b" and it worked fine, producing
output while the dir was still spinning (obviously setting shell=True
to make that work, but I don't think that'll make a difference). It
may be that pip buffers its output. Is there a parameter to pip to
make it pipe-compatible?

ChrisA

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


Thread

Running a command line program and reading the result as it runs Ian Simcock <Ian.Simcock@Internode.on.net> - 2013-08-22 15:21 +0930
  Re: Running a command line program and reading the result as it runs Chris Angelico <rosuav@gmail.com> - 2013-08-22 16:22 +1000
    Re: Running a command line program and reading the result as it runs Ian Simcock <Ian.Simcock@Internode.on.net> - 2013-08-23 00:56 +0930
      Re: Running a command line program and reading the result as it runs Chris Angelico <rosuav@gmail.com> - 2013-08-23 01:33 +1000
        Re: Running a command line program and reading the result as it runs Ian Simcock <Ian.Simcock@Internode.on.net> - 2013-08-23 16:22 +0930
        Re: Running a command line program and reading the result as it runs Grant Edwards <invalid@invalid.invalid> - 2013-08-23 14:02 +0000
  Re: Running a command line program and reading the result as it runs Rob Wolfe <rw@smsnet.pl> - 2013-08-22 23:14 +0200
    Re: Running a command line program and reading the result as it runs Ian Simcock <Ian.Simcock@Internode.on.net> - 2013-08-23 16:31 +0930
  Re: Running a command line program and reading the result as it runs Gertjan Klein <gklein@xs4all.nl> - 2013-08-23 11:32 +0200
  Re: Running a command line program and reading the result as it runs Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-23 11:53 +0200
  Re: Running a command line program and reading the result as it runs Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-23 12:34 +0200
  RE: Running a command line program and reading the result as it runs "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-08-23 10:50 +0000
  Re: Running a command line program and reading the result as it runs Peter Otten <__peter__@web.de> - 2013-08-23 13:14 +0200
    Re: Running a command line program and reading the result as it runs Gertjan Klein <gklein@xs4all.nl> - 2013-08-23 14:03 +0200
    Re: Running a command line program and reading the result as it runs Ian Simcock <Ian.Simcock@Internode.on.net> - 2013-08-24 19:06 +0930
  Re: Running a command line program and reading the result as it runs random832@fastmail.us - 2013-08-23 12:04 -0400
  Re: Running a command line program and reading the result as it runs Peter Otten <__peter__@web.de> - 2013-08-23 18:39 +0200

csiph-web