fork & exec a process?

Jim Meier jim at home.com
Mon Nov 26 06:44:07 EST 2001


Hi, I know this has been covered many times before but I can't seem to
find it anywhere.

I'm trying to fork & exec a process, and be able to read it's output
to stderr and stdout. 

It looks like my changes to the stderr and stdout fds aren't getting
seen after the exec (or so I read in a cached article by Guido I
managed to find on google).

I've also tried a popen trick as mentioned in that file, of opening a
pipe and using popen with redirection to it;

out_read, out_write = os.pipe()
err_read, err_write = os.pipe()
ret = os.popen("command >&%d 2>&%d" % (out_write, err_write))


and then reading from out_read and err_read. The problem with this
approach is that i can't tell when the process dies - except by
calling ret.close(), and blocking until it does close.

The purpose of all this is to execute some long-running programs (like
ping) and collect their results, while still processing the rest of
what needs to be done.

There must be a way to do this, what am I missing?

-Jim



More information about the Python-list mailing list