views:

413

answers:

2

There are similar questions to this one, but I'd like to see a clarified answer. I'm building a simple GUI with PythonCard to wrap a command line process. Specifically, it's a wrapper for a series of ANT Tasks and other custom operations so non-devs can use it.

I'd like to redirect the output of the subprocess to a TextArea in the window. It looks like the way to do this is to use subprocess.Popen(command, stdout=subprocess.PIPE) and load the output to a variable.

The question is how do I live update the window with the output of the subprocess? Any hints would be welcome

Thanks

+1  A: 

Just about every subprocess you can wrap will buffer its output unless you manage to fool it into believing it's actually connected to a terminal -- and subprocess can't do that. Rather, look into pexpect (runs well on every platform that lets you have a pseudoterminal, i.e., every platform except Microsoft Windows; on Windows you might try wexpect but I have no experience with the latter).

These modules give you the subprocess's output as soon as it's produced, and strive to fool the module into producing that output ASAP and without buffering, so they should make it easy for you to receive that output in real time and append it to the text field you want to keep updating.

Alex Martelli
+1  A: 
ecs1749