Accessing external file output from script?

P

PWR

Platform: Windows
Python: 2.3
Python Skill: Reading, Learning, but still newbie.

Mission: My mission is writing a script that is triggered from my mail
server. The script will execute and download a file. The email that
triggered the message has a file size which is compared to the
downloaded file to make sure the bytes match. Once that is accomplished
there is a small program (.exe) that I can run against the file. The
..exe has two outputs...

If the file that was downloaded is intact is returns nothing

If the file is damaged or not correct it returned ERROR_XXX

Those are the only things it will return.

Is there a way to call this program to run from my script and then
parse? the output to see if either state is returned?

The good news is the script runs and does everything but the external
file check (woo) so I am making progress.


-P.
 
C

Cameron Laird

Platform: Windows
Python: 2.3
Python Skill: Reading, Learning, but still newbie.

Mission: My mission is writing a script that is triggered from my mail
server. The script will execute and download a file. The email that
triggered the message has a file size which is compared to the
downloaded file to make sure the bytes match. Once that is accomplished
there is a small program (.exe) that I can run against the file. The
.exe has two outputs...

If the file that was downloaded is intact is returns nothing

If the file is damaged or not correct it returned ERROR_XXX

Those are the only things it will return.

Is there a way to call this program to run from my script and then
parse? the output to see if either state is returned?

The good news is the script runs and does everything but the external
file check (woo) so I am making progress.
.
.
.
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?
 
J

Josiah Carlson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top