newbie pipes question

teo teo at crepido.com
Thu Jul 26 07:25:45 EDT 2001


David Lees <DavidLnospammy at raqia.com> wrote in message news:<3B58494D.C82965AD at raqia.com>...

> I am running under redhat 7.1 with python 2.1 and want to have python

> process the output of a perl script.

> 

> I execute the perl script from python as:

> 

> os.system("regex2.pl -o junky 'birds'")

> 

> and the output goes to my screen, presumably stdout.

> 

> I can redirect the output to a temporary file and read it pack into

> python, but the right way would seem to be pipes.  Can someone tell me

> how to do this?  I tried the following, which does not work, because it

> seems to hang on the os.read statement:

> 

> r,w=os.pipe()

> os.system("regex2.pl -o junky 'birds'")

> x=os.read(r,100)

> print x

> 

> Thanks in advance,

> 

> david lees


Try this instead:

 pipe = os.popen("regex2.pl -o junky 'birds'")
 for line in pipe.readlines()
   print line

/teo



More information about the Python-list mailing list