subprocess.Popen() redirecting to TKinter or WXPython textwidget???
Ivo Woltring
TheDolphin at ivonet.nl
Wed Jan 26 16:56:12 EST 2005
<stewart.midwinter at gmail.com> wrote in message
news:1106775371.049857.36360 at z14g2000cwz.googlegroups.com...
> Ivo, my initial thought would be, you need to know how much text you
> will get back from popen. My Python reference has the following
> example:
>
> import os
> dir = os.popen('ls -al', 'r')
> while (1):
> line = dir.readline()
> if line:
> print line,
> else:
> break
>
> that example shows how to capture the process output in a file-type
> object, then bring it into a string with readline().
>
>[.... snip ....]
> cheers
> S
>
Thanx for trying Stewart,
but that is not what I need
The output of mencoder is not readable with readlines (i tried it) because
after the initial informational lines You don't get lines anymore (you get a
linefeed but no newline)
The prints are all on the same line (like a status line)
something like
Pos: 3,1s 96f ( 0%) 42fps Trem: 0min 0mb A-V:0,038 [171:63]
which is coninually updated while the process runs...
> in your app, you could create a Tkinter stringVar, say myOutput, for
> the process output. In your Tkinter widget, you could then set a
> textvariable=myOutput. also use the wait_variable and watch options
How does this work? wait?? anyone?
> (hope I recall these correctly, don't have my Tkinter ref. at hand) to
> detect when there's been a change to the contents of the StringVar and
> update the contents of the label.
> Hope this helps, if not, write back.
I really like to know how I can catch the output of a subproces.Popen()
command and redirect it to something else (like a textwidget )
and I really like to use the subprocess module (standard in v2.4) to get to
know it.
Another reason to use the subprocess module is I can stop the process
because I know the handle of the thread. The subprocess module knows all
this.
cheerz,
Ivo.
More information about the Python-list
mailing list