I've written a new popen-like module for Python. This module overcomes several limitations with the old popen2 module, but also aims to be a generic module for starting and communicating with processes on POSIX systems. It can replace several older modules and functions, like:
os.system os.spawn os.popen popen2. commands.
This module features:
Cross-process exceptions: Exceptions happening in the child before the new process has started to execute are re-raised in the parent. This means that it's easy to handle exec() failures, for example. With popen2, it's impossible to detect if the execution failed.
A hook for executing customized code between fork and exec. This can be used for, for example, changing uid.
No implicit call of /bin/sh. This means that there is no need for escaping dangerous shell meta characters.
A communicate() method, which makes it easy to send stdin data and read stdout and stderr data, without risking deadlocks.
Support for connecting several subprocesses (shell "pipe").
The module is available from http://cvs.lysator.liu.se/viewcvs/viewcvs.cgi/popen5/?cvsroot=python-popen5, or via anonymous CVS (:pserver:email@example.com:/cvsroot/python-popen5).
All feedback is appreciated.
/Peter Åstrand firstname.lastname@example.org