stdout redirect : Howto with popen2.popen3

Fabien Hénon ffjhenon at club-internet.fr
Sat Apr 6 18:54:41 EST 2002


I want to use Tkinter to launch a raytracer that can last from 1 second
to several days.
That raytracer displays an image in an external box and the line which
is being raytraced to the console.
Once the raytracing process is over, it outputs stats or an error
message if something goes
is wrong in the script.

For the time being, all I managed to get is the image box and a file
with the stats.

  1° I would like the stats to be returned straight to a Tkinter window.

I use popen as shown below.

  2° How can I tell when the raytrace is over ? The poll() gets out of
the loop.
What is command to listen to a program to tell if it's running or not?



###     pin,pout = os.popen2(cm )       ## these two lines
###     pin,pout,perr = os.popen3(cm )  ## do not work



cm="command 2> sortie.txt"
run=popen2.Popen3(cm)
pi=run.pid
pid=pi+1
while run.poll() <>-1:
     print "attente"   # // I never got to here and goes straight to
fd=open.....


fd=open("sortie.txt")  # // reads the file created by the pipe
for line in fd.readlines():
     if line.endswith("\r"):
         line=line[:-2]+"\n"
         self.text_out.insert(END,line)  # // inserts the file in the
Tkinter box
                           // from the previous raytrace .......




Thanks for any help





More information about the Python-list mailing list