[pygtk] vte terminal, incomplete output of child process

Jan Martinek honza at dp.fce.vutbr.cz
Thu Mar 13 20:17:40 WST 2008


Hello,

I want to run an external program in terminal (vte) and after the 
program exits, I want to read a couple of last lines of the output.

For testing purposes I tried this

#!/usr/bin/python

import vte, gtk, time

def capture_text(vt, foo, bar, baz):
     return True

def on_child_exited(vt):
     text = t.get_text(capture_text)
     print text

def on_button_clicked(but, t):
     t.fork_command('/bin/ls')

t = vte.Terminal()
t.connect('child-exited', on_child_exited)
t.fork_command('/bin/ls', argv = ['/bin/ls', '/etc'])

w = gtk.Window()
w.connect('destroy', gtk.main_quit)
w.add(t)
w.show_all()
gtk.main()

And it works, but the output is not complete. Is there any buffering, 
race condition or something?

If someone is interested of what I need it for:
I want to parse traceback of a python program and get the line number 
and filename where the exception was found. Redirecting of the output is 
unfortunately not a solution because of buffering. The output file 
descriptor must be a real tty.

Thank you
Jan Martinek


More information about the pygtk mailing list