os.system easy question
Erno Kuusela
erno-news at erno.iki.fi
Tue Jan 23 06:39:35 EST 2001
In article <slrn96qrgp.gg.huwdotlynes at Marvin.ic.ac.uk>,
huwdotlynes at ic.ac.uk (Huw Lynes) writes:
| how to kill the
| external program after it has run. Or alternatively how to
| run an external program in such a way that the script will
| not halt.
do something like...
import signal, os
class BgProc:
def __init__(self, cmdline):
pid = os.fork()
if pid > 0:
self.pid = pid
else:
try:
os.execvp('/bin/sh', ['sh', '-c', cmdline])
finally:
os._exit(255)
def wait(self):
return os.waitpid(self.pid, 0)
def kill(self, sig = signal.SIGTERM):
os.kill(self.pid, sig)
return self.wait()
-- erno
More information about the Python-list
mailing list