[Tutor] pipes

Remco Gerlich scarblac@pino.selwerd.nl
Mon, 21 May 2001 17:39:05 +0200


On  0, Eugene Leitl <Eugene.Leitl@lrz.uni-muenchen.de> wrote:
> How do I hook up the output of below to the second program?
> 
> import os, sys
> 
> pipe = os.popen('webdsp1')
> print pipe.read()

You can also write to programs opened with os.popen:

program1 = os.popen('webdsp1', 'r')
program2 = os.popen('dispreact', 'w')
program2.write(program1.read())

Done this way, the programs don't run at the same time: first Python reads
in all the output from program1, then it passes it all to program2. If that
isn't good enough you can read from program1 in smaller chunks and pass
those to program2, in a loop.

-- 
Remco Gerlich