portable fork+exec/spawn

Brendan Miller catphive at catphive.net
Thu May 1 22:17:34 EDT 2008


I want to spawn a child process based on an external executable that I have
the path for. I then want to wait on that executable, and capture it's
output.

In the os module, fork is only supported on unix, but spawn is only
supported on windows.

The os.system call is implemented by calling the C system call, which is of
course inefficient and has portability gotchas because it calls the
underlying system shell (sh for unix, cmd for windows, and who knows what
on non unix, non windows platforms like VMS and mac os9). Most importantly,
os.system forces you to wait on the process.

Is there an actual portable means of asynchronously spawning a process and
getting a handle to it, being able to write stdin and read stdout, or does
everyone just write their own wrapper for fork and spawn?

Sorry if this post sounds a little complainy. I was just surprised to find
the os module lacking in portable abstractions over system services.

Brendan



More information about the Python-list mailing list