POpen - Wait For Process To Complete

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Tue Jul 3 10:49:39 EDT 2007


Hello guys,

 

Quite a simple one I'm hoping. I've got a process that I run using popen
which writes to a file, I'm then going to read the file and parse its
contents. However, getting the application to wait until the process is
complete and finished writing before it reads and parses the file is
becoming complicated.

 

Popen is meant to have a wait() function along with a poll() function
(according to the docs), both of which can be used to make the app wait for
the process to finished, but for some reason I can't get them working, when
I try this:

                                

                                Import popen2

                                

              Process = popen2.popen4('This is my command to run from cmd')

 

              Process.wait()

 

              f = open('path/to/output/file.txt')

              new = f.read()

              f.close()

 

It throws back the following error to me:

 

push.wait()

AttributeError: 'tuple' object has no attribute 'wait'

 

Which is fair enough as popen4 returns a tuple containing the output streams
from the cmd command, but how the hell can I have it wait so I can read the
physical files?

 

I'll be interested to hear your thoughts guys,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070703/de5c22f8/attachment.html>


More information about the Python-list mailing list