Start and control an extern program
Noah
noah at noah.org
Tue Mar 16 14:14:43 EST 2004
Axel Koehler <axel.koehler at tu-berlin.de> wrote in message news:<kpd67jfdk4.fsf at rosebud.gp.tu-berlin.de>...
> Hallo,
> I want to start an extern program and simple stop it, after a
> given time, if not succesfull finished.
> OS is Linux
> Axel
You could try the Pexpect library.
http://pexpect.sourceforge.net/
It allows you to start an external program and then wait for a given result
with a given timeout. Pexpect has a default timeout of 30 seconds, but
you can change that. The result that you are looking for can be
any string that you expect in the output. The string can be a
regular expression pattern. So you could write code like this:
import pexpect
child = pexpect.spawn ('my_external_program', timeout=120) # Two minute timeout.
index = p.expect (['results_you_are_looking_for', pexpect.TIMEOUT])
if index == 0:
do_something ()
elif index == 1:
child.kill (9)
child.close ()
Yours,
Noah
More information about the Python-list
mailing list