Accessing external file output from script?

Josiah Carlson jcarlson at nospam.uci.edu
Wed Feb 11 15:36:37 EST 2004


> I believe you are saying that you want to know a Python idiom
> for launching an external application (MY_SMALL_PROGRAM.exe?),
> perhaps with a command-line argument or two, and collect its
> result back into a Python variable for subsequent processing.
> Is that correct?  What does "return" mean to you in this con-
> text?  Are you saying that MY_SMALL_PROGRAM.exe puts specific
> output such as "ERROR_XXX" to its stdout (or stderr?), or is
> your focus on the process's exit status?
> 
> I suspect you'll end up reading <URL:
> http://python.org/doc/current/lib/module-popen2.html >.
> 
> Question for the audience:  what are the impediments to making
> <URL: http://python.org/doc/current/lib/module-commands.html >
> available for Windows?

I don't know if there are many, other than the format of the os.popen 
call of commands.getstatusoutput not being understandable to Windows.

On windows, I usually use the following:

def getoutput(cmdline):
     fil = os.popen(cmdline, 'r')
     output = fil.read()
     fil.close()
     return output

But I don't bother with the status output.

The reasons may be related to the windows specifics required for 
os.popen5 that should be included in some future Python release.

  - Josiah



More information about the Python-list mailing list