os.system() or os.execv() w/stdout redirect and PID tracking

Michael Olivier dmtech at iname.com
Thu May 6 13:13:17 EDT 1999


Hi folks,

What's the best way from a python program to start another program in
the background and:
- redirect stdout/stderr to a file
- get the process ID of the started program.

It seems that:

- os.system() call can start a program in the background, but doesn't
return the pid (process ID) of the started program -- returns 0

    os.system("find / -name mic* -print > /tmp/find-cmd 2>&1 &")

    This does what I want but don't get the PID back for it

- if I call os.fork() and then os.execv(), the pid is trackable,
but I don't know a way to redirect stdout/stderr

Suggestions?

thanks,
Michael




More information about the Python-list mailing list