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

2013-08-24 Thread Ian Simcock
Peter Otten wrote: Ian Simcock wrote: Greetings all. I'm using Python 2.7 under Windows and am trying to run a command line program and process the programs output as it is running. A number of web searches have indicated that the following code would work. import subprocess p = subprocess.P

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

2013-08-23 Thread Peter Otten
random...@fastmail.us wrote: > On Fri, Aug 23, 2013, at 7:14, Peter Otten wrote: >> The following works on my linux system: >> >> instream = iter(p.stdout.readline, "") >> >> for line in instream: >> print line.rstrip() >> >> I don't have Windows available to test, but if it works t

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

2013-08-23 Thread random832
On Fri, Aug 23, 2013, at 7:14, Peter Otten wrote: > The following works on my linux system: > > instream = iter(p.stdout.readline, "") > > for line in instream: > print line.rstrip() > > I don't have Windows available to test, but if it works there, too, the > problem is the interna

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

2013-08-23 Thread Grant Edwards
On 2013-08-22, Chris Angelico wrote: > On Fri, Aug 23, 2013 at 1:26 AM, Ian Simcock > wrote: >> Chris Angelico wrote: >>> >>> 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 sti

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

2013-08-23 Thread Gertjan Klein
Peter Otten wrote: The following works on my linux system: import subprocess p = subprocess.Popen( ["ping", "google.com"], stdout=subprocess.PIPE) instream = iter(p.stdout.readline, "") for line in instream: print line.rstrip() I don't have Windows available to test, but if i

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

2013-08-23 Thread Peter Otten
Ian Simcock wrote: > Greetings all. > > I'm using Python 2.7 under Windows and am trying to run a command line > program and process the programs output as it is running. A number of > web searches have indicated that the following code would work. > > import subprocess > > p = subprocess.Popen

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

2013-08-23 Thread Joseph L. Casale
> >> I'm using Python 2.7 under Windows and am trying to run a command line > >> program and process the programs output as it is running. A number of > >> web searches have indicated that the following code would work. > >> > >> import subprocess > >> > >> p = subprocess.Popen("D:\Python\Python27\

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

2013-08-23 Thread Antoon Pardon
Op 23-08-13 11:53, Antoon Pardon schreef: > Op 22-08-13 07:51, Ian Simcock schreef: >> Greetings all. >> >> I'm using Python 2.7 under Windows and am trying to run a command line >> program and process the programs output as it is running. A number of >> web searches have indicated that the followi

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

2013-08-23 Thread Antoon Pardon
Op 22-08-13 07:51, Ian Simcock schreef: > Greetings all. > > I'm using Python 2.7 under Windows and am trying to run a command line > program and process the programs output as it is running. A number of > web searches have indicated that the following code would work. > > import subprocess > >

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

2013-08-23 Thread Gertjan Klein
Ian Simcock 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

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

2013-08-23 Thread Ian Simcock
Rob Wolfe wrote: Ian Simcock writes: When file object is used in a for loop it works like an iterator and then it uses a hidden read-ahead buffer. It might cause this kind of blocking. You can read more details here (description of method ``next``): http://docs.python.org/lib/bltin-file-objects

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

2013-08-22 Thread Ian Simcock
Chris Angelico wrote: On Fri, Aug 23, 2013 at 1:26 AM, Ian Simcock wrote: Chris Angelico wrote: A lot of programs, when their output is not going to the console, will buffer output. It's more efficient for many purposes. With Unix utilities, there's often a parameter like --pipe or --unbuff

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

2013-08-22 Thread Rob Wolfe
Ian Simcock writes: > Greetings all. > > I'm using Python 2.7 under Windows and am trying to run a command line > program and process the programs output as it is running. A number of > web searches have indicated that the following code would work. > > import subprocess > > p = subprocess.Popen(

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

2013-08-22 Thread Chris Angelico
On Fri, Aug 23, 2013 at 1:26 AM, Ian Simcock wrote: > Chris Angelico wrote: >> >> 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 >> t

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

2013-08-22 Thread Ian Simcock
Chris Angelico wrote: 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 m

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

2013-08-21 Thread Chris Angelico
On Thu, Aug 22, 2013 at 3:51 PM, Ian Simcock 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, the