Should I close after popen??

Donn Cave donn at oz.net
Sun Mar 18 01:01:00 EST 2001


Quoth Andrew Markebo <flognat at flognat.myip.org>:
| / Donn Cave <donn at oz.net> wrote:
| Basically, run two or more popens in parallell, and when there is data
| on one of them read it and do some work.. 
|
| Basically what I do now is do two popen2, do a wait on the first, chew
| some data, wait for the second, not critical at the moment, just
| interested what to do if I had to chew the data from the second
| process first.

Given two or more inputs, select() is the way to find out which one
is readable.  "Readable" means os.read() will return right away, with
either data or an empty string indicating the pipe was closed.  Any
I/O on the file object will severely confuse the issue.

...
|| One unrelated advantage of popen2 is that if you supply a list of
|| arguments, it will use them directly instead of a shell command
|| line.  That is much safer.  A command line constructed at run
|
| You mean like popen2(["command", "param", "param"]...)?

Right.  (For the same difference vs. system(), use spawnv().)

	Donn Cave, donn at oz.net



More information about the Python-list mailing list