managing stdout and stderr neatly while doing parallel processing

Grant Edwards grante at visi.com
Wed Aug 6 04:27:14 CEST 2003


In article <bgp3li$5l8$1 at news-reader2.wanadoo.fr>, Andrei D. wrote:

> Anyway, what I wanted to ask was about managing the output of stderr as well
> as stdout, using select.select and your common garden os.popen in this case.

Sorry, can't be done.  os.popen() returns a pipe that is hooked to stdout.
stderr is still going to where it was before.  The stderr stream isn't being
handled by your Python program at all.

You've got a several options:

 1) use os.popen3(), so that you get separate pipes for stdout and stderr.
 
 2) use os.popen4(), so that you get a pipe with combined stdout+stderr.
 
 3) use a pseudo-terminal (pty) so that your child process is running in a
    more "natural" environment, and you'll get both stderr and stdout that
    way too.  Don't know if there's handy Python "pty" module or not...
    
Some programs act differently when attached to ttys than they do when
attached to pipes.  If this is a problem, 3) is what you'll need to do.    

-- 
Grant Edwards                   grante             Yow!  ... I want a COLOR
                                  at               T.V. and a VIBRATING BED!!!
                               visi.com            




More information about the Python-list mailing list