show in GUI stdout of a command

T

twigster

Hi,

I need to display in real time the output of a command line tool in a
GUI written so far with Tkinter and Pmw. I've got a command line tool
that I want to integrate to a GUI. The parameters are set using the GUI
and a button executes the command. The calc is long so I need to see how
fast it goes. This is given by the stdout...

any idea how to do this?

thanks
Alexandre
 
N

Noah

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
 
I

Ian Parker

twigster said:
Hi,

I need to display in real time the output of a command line tool in a
GUI written so far with Tkinter and Pmw. I've got a command line tool
that I want to integrate to a GUI. The parameters are set using the GUI
and a button executes the command. The calc is long so I need to see
how fast it goes. This is given by the stdout...

any idea how to do this?

thanks
Alexandre

Full of Christmas spirit, I'll suggest a look at
http://lfw.org/python/Console.py
I find it a few days ago when I was hunting for a way to "print" to the
tkinter window rather than stdout.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,274
Messages
2,571,368
Members
48,060
Latest member
JerrodSimc

Latest Threads

Top