python executing windows exe

Larry Bates larry.bates at websafe.com
Thu Feb 1 18:13:29 EST 2007


Kiran wrote:
> Hi everybody,
>   I am making python run an executable using the os module.  Here is
> my question.  The executable, once it is running, asks the user to
> input a filename that it will process.  Now, my question is how do i
> automate this.  let me make this clear, it is not an argument you pass
> in when you type in the exe.  An example below illustrates:
> 
> THIS IS NOT WHAT YOU DO:
> nec2d.exe couple1.nec                         # couple1.nec is the
> file you want to prcess
> 
> rather, what you do is in windows cmd:
> 
> nec2d.exe
> **** PROGRAM PRINTS OUT STUFF*****
> **** PROGRAM PRINTS OUT STUFF*****
> **** PROGRAM PRINTS OUT STUFF*****
> **** PROGRAM PRINTS OUT STUFF*****
> Please enter input file:  <--------- THIS IS WHERE THE USER IS ASKED
> TO TYPE IN THE FILENAME
> 
> everybody thanks for your help
> -- Kiran
> 
Not exactly a Python question, but here goes.  Normally I do this
by piping the response into the executable.  Something like:

nec2d.exe <filename.txt

That way the program reads the filename that is provided by filename.txt.
You would of course write the name of the file you want processed into
filename.txt prior to doing this.  Try it by hand first to make sure the
program doesn't do something smart like not read from stdin.

-Larry



More information about the Python-list mailing list