Python Printing StdOut As It Received
Question: I'm trying to run wrap a simple (windows) command line tool up in a PyQt GUI
app that I am writing. The problem I have is that the command line tool throws
it's progress out to stdout (it's a server reset command so you get
"Attempting to stop" and "Restarting" type output.

What I am trying to do is capture the output so I can display it as part of my
app. I assumed it would be quite simple to do something like the following :

    
    
    import os
    import subprocess as sub
    cmd = "COMMAND LINE APP NAME -ARGS"
    proc = sub.Popen(cmd, shell=True, stdout=sub.PIPE).stdout
    while 1:
        line = proc.readline()
        if not line: 
            break
    print line
    

This partially works in that I do get the contents of StdOut but instead of as
the progress messages are sent I get it once the command line application
exits and it seems to flush StdOut in one go.

Is there a simple answer?


Answer: Interactive communication through stdin/stdout is a common problem.

You're in luck though, with PyQt you can use QProcess, as described here:
[http://diotavelli.net/PyQtWiki/Capturing_Output_from_a_Process](http://diotavelli.net/PyQtWiki/Capturing%5FOutput%5Ffrom%5Fa%5FProcess)

