Search code examples
pythonuser-interfaceglade

Python GUI (glade) to display output of shell process


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?


Solution

  • 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_object('txtview')
    proc = subprocess.Popen('ls -al /home'.split(), stdout=subprocess.PIPE, stderr = subprocess.STDOUT)
    while True:
        line = proc.stdout.readline()
        viewer.get_buffer().insert_at_cursor(line)
        if not line:
           break