do I need popen or something else

P_spam_ at draigBrady.com P_spam_ at draigBrady.com
Fri Dec 13 07:19:51 EST 2002


HardYards wrote:
> The problem is that I have a program that performs a lot of numerical
> computation and as it runs through it tells the user what it is doing.
> (If it's a real big run - it's a batch job - but that is a different
> question)
> 
> Because of the humungous files that it produces I would like to wrap
> it in a python script that runs it and when it is finished zips up the
> output files.
> 
> This way the python/VTK program I have put together for displaying
> them can simply unzip them and we are away.  The alternative is to
> link zlib into my c code - but that is not tidy..
> 
> Anyway going through the python groups it looks like I need 
> 
> popen("myappname.exe")
> 
> the trouble is that popen seems to want the app to finish before it
> sends back any output - or am I missing something.
> 
> What I want is a way to execute the program and direct output to
> stdout in real time

Well if you don't want to parse the output you can just:
os.system("myappname.exe") and the output will go
to sys.stdout

If you do want to parse the output, then you need popen
but you should be aware of the buffering. The 3rd Q/A
at http://pexpect.sourceforge.net/#faq has good info on this.

Pádraig.




More information about the Python-list mailing list