subprocess.Popen - file like object from stdout=PIPE

Helmut Jarausch jarausch at skynet.be
Wed Feb 4 04:22:13 EST 2009


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 :
   ...

I could use StringIO.StringIO applied to EQ_output
but this reads all of the command's output into a big
string first.

On Unix/Linux a pipe is a file-like object after all,
so how to get hold of it.


Many thanks for a hint,
Helmut.

-- 
Helmut Jarausch

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



More information about the Python-list mailing list