python executing windows exe

K

Kiran

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
 
L

Larry Bates

Kiran said:
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
 
G

Gabriel Genellina

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:

You can use the subprocess module, or any of the Popen2 variants. Usually
they work fine - but depending on how the application behaves, it may not
work.
 
A

aspineux

First look if your .exe will accept to work that way !
try in a DOS prompt
echo yourfilename | nec2d.exe

or if the program expect more input, write them all in a file
( myinputs.txt ) and try :
nec2d.exe < myinputs.txt

If it works looks for module subprocess and more precisely object
subprocess.popen and method comunicate
 
K

Kiran

First look if your .exe will accept to work that way !
try in a DOS prompt


or if the program expect more input, write them all in a file
( myinputs.txt ) and try :


If it works looks for module subprocess and more precisely object
subprocess.popen and method comunicate
Hi everybody,
What you guys said helped out a lot and I got it to do what I
wanted.

thanks!,
Kiran
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top