subprocess.Popen - file like object from stdout=PIPE

Helmut Jarausch jarausch at skynet.be
Wed Feb 4 05:48:42 EST 2009


Chris Rebert wrote:
> On Wed, Feb 4, 2009 at 1:22 AM, Helmut Jarausch <jarausch at skynet.be> wrote:
>> Hi,
>>
>> using e.g.
>> import subprocess
>> Package='app-arch/lzma-utils'
>> EQ=subprocess.Popen(['/usr/bin/equery','depends',Package],stdout=subprocess.PIPE)
>> EQ_output= EQ.communicate()[0]
>>
>> EQ_output is a string containing multiple lines.
>>
>> I'd prefer a file-like object, e.g. EQ_OUT
>> so that I can loop over the lines of it like
>>
>> for line in EQ_OUT :
>>  ...
> 
> Is there some reason that:
> 
> for line in EQ_OUT.splitlines():
>     #...
> 
> Does not meet your needs?
> 

It works, but it still reads the complete output of the
command executed by Popen at once.

Helmut.


-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany



More information about the Python-list mailing list