show in GUI stdout of a command
Noah
noah at noah.org
Mon Dec 19 21:17:57 EST 2005
Try Pexpect for running your command interactively
http://pexpect.sourceforge.net/
For example, if you wanted to run the "top" command you could
use a script like below. This updates the output every 5 seconds.
You can easily adjust the timeout.
---------------------------------------------------------------
import pexpect
def progress_callback (d):
"""This callback updates child command output.
This is used when running external commands
with pexpect.run.The callback is given a dictionary
of the local variables in pexpect.run. This explains
the syntax of d['child'].before, which you would
otherwise simple enter as child.before.
"""
print d['child'].before
pexpect.run("top", timeout=5,
events={pexpect.TIMEOUT:progress_callback})
---------------------------------------------------------------
Next you would then have to add that whole
GUI thing yourself :-)
You can also try using pipes (popen and friends), but the
output will be block buffered, so it would come out chunky
and not in real time. There is no way to change the child's
buffering from block buffering to line buffering without using
a pseudo-TTY.
Yours,
Noah
More information about the Python-list
mailing list