waiting for a program run by popen3() to end

Miki Tebeka mikit at zoran.co.il
Wed Oct 15 04:55:32 EDT 2003


Hello Rajarshi,

>         o,i,e = os.popen3('/usr/local/adapt/bin/descmng -g')
>         o.write('\n%s\n\n' % (redpick))
>         o.close()
>         time.sleep(1)
>         os.system('mv set5 gendes.in && rm set? outputdesc.txt')
If you're not reading the program output you can use os.system which
will wait for it to end.

> Is there any other way out (apart from dumping commands to a file and
> piping them to my program in a fork())?
On Unix like systems there is popen2.Popen3 (or Popen4)
---
from popen2 import Popen3

print "Running child"
p = Popen4("my_process arg1 arg2")
print "Waiting"
p.wait() # Will wait for process to end
print "And we got:"
print p.fromchild.read()
---

HTH.
Miki




More information about the Python-list mailing list