[Tutor] pipes

Eugene.Leitl@lrz.uni-muenchen.de Eugene.Leitl@lrz.uni-muenchen.de
Tue, 22 May 2001 00:48:20 +0200


Remco Gerlich wrote:

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

Thanks a lot. I'll try that tomorrow. Lack of concurrency is actually 
an advantage, since the total output is small (few kBytes), and it should
be able to run as many platforms as possible without having to tweak
anything.

If it wasn't for time constraints I'd avoid calling any external
binaries, and rather use gdmodule instead (I know PIL would have
been probably better, but current app has been using GD for time 
immemorial, and via GD.pm, so remapping that into Python wouldn't
have cost me as much as doing it in C (I don't know C either)).