show in GUI stdout of a command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • twigster

    #1

    show in GUI stdout of a command

    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
  • Noah

    #2
    Re: show in GUI stdout of a command

    Try Pexpect for running your command interactively
    Download Pexpect - Pure Python Expect-like module for free. Pexpect is a Python module for spawning child applications; controlling them;


    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_callba ck (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("to p", timeout=5,
    events={pexpect .TIMEOUT:progre ss_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

    Comment

    • Ian Parker

      #3
      Re: show in GUI stdout of a command

      In message <43a6fa19$0$288 $636a55ce@news. free.fr>, twigster
      <twigsterREMOVE @THISmelix.net> writes[color=blue]
      >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[/color]

      Full of Christmas spirit, I'll suggest a look at

      I find it a few days ago when I was hunting for a way to "print" to the
      tkinter window rather than stdout.

      Regards
      --
      Ian Parker

      Comment

      Working...