I'm writing a python application that runs several subprocesses using subprocess.Popen objects. I have a glade GUI and want to display the output of these commands (running in subprocess.Popen) in the gui in real time.
Can anyone suggest a way to do this? What glade object do I need to use and how to redirect the output?Answer1:
Here is a link that also displays another way of doing this.
I found this to be very insightful, maybe someone else can use these tips.
<a href="http://pygabriel.wordpress.com/2009/07/27/redirecting-the-stdout-on-a-gtk-textview/" rel="nofollow">http://pygabriel.wordpress.com/2009/07/27/redirecting-the-stdout-on-a-gtk-textview/</a>Answer2:
glade is only a program to build gui with gtk so when you ask for a <em>glade object</em> maybe you should ask for <em>gtk widget</em> and in this case textbuffer and textview chould be a solution or maybe treeview and liststore.
stderr arguments that can accept a file-like object. you can create an adapter that writes to the textbuffer or add items in the liststore
After lots of reading and not getting the results I wanted, I found another method that works.
It goes like this
#!/usr/bine/env python import subprocess import gtk ### Of course, you should have the gui built and know which widgets to use for this. viewer = self.builder.get_widget('txtview') proc = subprocess.Popen('ls -al /home'.split(), stdout=subprocess.PIPE, stderr = subprocess.STDOUT) while True: line = proc.stdout.readline() viewer.get_buffer().instert_at_cursor(line) if not line: break