Using python to check the status of a program
The Jetman
jetman516 at hotmail.com
Sat Dec 27 17:24:29 EST 2003
Kamuela Franco <kamuelaf at verizon.net> wrote in message news:<pan.2003.12.27.10.53.23.520358 at verizon.net>...
> I would like to use a Python script to periodically check to see if a
> program is still running and if it isn't I want to start it up. Could
> someone point me on the right path? Thanks in advance.
>
> Kamuela
1st, which OS are we talking about ? *IF* we're talking about
Linux/Unix/FreeBSD, then it only takes a few lines:
import os
import string
f = os.popen( 'ps -ax' )
s = f.readlines()
if string.find( s, 'target_pgm' ) > -1:
#### we found it, so do something....
If we're talking about Windows, then this would work using the
Cygwin utils for ps or one could try Pythonwin. Mark has ported
many Windows APIs, so it would be a little more involved, but
straight-fwd. HTH....Jet
More information about the Python-list
mailing list