Capture output from stderr

klappnase klappnase at web.de
Wed Aug 6 02:26:49 CEST 2003


Hello,

I am trying to program a Tkinter application for linux, so I want to
run a shell command from the gui and capture its output on the fly
while the process is still running in order to display the progress
messages in a toplevel window so the user may watch what is going on
(the execution of the shell command may take a few minutes). Because
the output is printed to stderr I thought I should use a popen2.Popen4
instance for that, like:

        self.pp = popen2.Popen4("exec cmd")

I tried something like 

    def getmsg(self):
        msg = self.pp.fromchild
        newmsg = msg.read(100)
        ...(do something)...
        self.master.after(1000, self.getmsg)

to get the output, but this way the process gets horribly slowed down
and even if it worked it would be hard to check the whole output for
the information that I want to be displayed.
I think I would need something like 

    self.pp.readlines()

but this only returns after the process has finished.

Does anyone know how to handle this?
I would be very thankful for any help.

Michael




More information about the Python-list mailing list