69284

Python GUI (glade) to display output of shell process

Question:

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. subprocess.Popen has stdout and 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

Answer3:

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

Recommend

  • In a master-master setup, what command or files do I edit so that it can auto-increment by 2?
  • In GTK, how do I change the localized language text on the UI while it's running?
  • Can't compile project - VB.Net - Fatal error BC2000 - Xamarin/MonoDevelop
  • Gtkmm 3.0 library for Windows
  • Debug sales order workflow in OpenERP 6.1 web client
  • Disable right click in GTK window
  • draw an image to gtk.DrawingArea?
  • hashmap custom class key && object saving/loading
  • GTK# window not rendered completely
  • How do I convert a ResultSet in a List of Hashtable?
  • Link in Google search results is not redirected to expected page as per .htaccess
  • Excluding multiple values from the array
  • GTK/GDK Algorithm to take full screenshots of all monitors
  • dbus Variant: How to preserve boolean datatype in Python?
  • htaccess will not rewrite subdomains
  • byebug, next into application code only
  • Wordpress and Drupal SSO/Single Sign On
  • wordpress query - next two events by metadata date
  • Read stdin in chunks in Bash pipe
  • IIS 7.5 404 Error for .PDF files
  • Ionic storage “get” returns null only on the second call within method
  • Microsoft Excel Pivot miscalculation in Sum for positive and negative numbers
  • triggering user space with kernel
  • CSS - Cannot get one spanned style to override another inherited style and align left
  • XSLT foreach repeating nodes to flat
  • opencv display image without x server
  • Suppressing passwd when calling sqlplus from shell script
  • Redirect STDERR in OPEN pipe comand. Perl Linux
  • Webgrid not refreshing after delete MVC
  • Jquery UI tool tip close icon
  • Why is the size of this struct 32?
  • How would I use PHP exceptions to define a redirect?
  • How to handle AllServersUnavailable Exception
  • Traverse Array and Display in markup
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • need help with bizarre java.net.HttpURLConnection behavior
  • Turn off referential integrity in Derby? is it possible?
  • Qt: Run a script BEFORE make
  • JaxB to read class hierarchy