running and managing background shell commands
Dimitri Papadopoulos
papadopo at shfj.cea.fr
Wed Dec 15 12:45:53 EST 1999
Hi,
I am translating this shell function to Python:
_new_browser() {
# start Netscape in the background
# this will always return 0, even in the face of a failure...
netscape "$*" &
# ... so wait a few seconds, and check that Netscape is still alive
i=3
while [ $i -gt 0 ]
do
sleep 1
ps -p $! > /dev/null || return 1
i=`expr $i - 1`
done
return 0
}
How can I rewrite this function? As far as I know:
1) commands.getstatus cannot start a background command
2) os.system does start a background command
3) but $! is not available
Do I have to fork and then execv - which is probably what the shell does anyway?
More information about the Python-list
mailing list