Python reading output from a running, external process
Robert Amesz
sheershion at mailexpire.com
Wed Sep 10 17:47:36 EDT 2003
Matt Goodall wrote:
> Basically, os.popen() would allow you to execute the simulation
> tool and have its output channelled back to the GUI application
> through a file-like object.
>
> I don't know wx much but it is generally possible to attach a file
> (i.e. the file returned by popen) to the GUI's event queue so that
> one of your event handlers is called when there is new output from
> the simulation tool. It should be easy enough to parse that to
> update the UI.
In my experience it is *not* a good idea to use popen() in wxPython
apps, at least not under Windows: there seems to be some buffering
going on in popen(), totally ruining any sense of concurrency. Also,
reading the streams returned by popen() block, something to be avoided
at all costs in a GUI program. Finally, the process exit code is lost
when using popen().
Fortunately, in wxPython you can use a wxProcess, which doesn't buffer
or block, and can be polled using timer or idle events. There's an
example of how to use it in the wxPython demo.
Robert Amesz
More information about the Python-list
mailing list