Calling an exe file from a batch program

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
simplecode
Posts: 2
Joined: 14 Jan 2011 10:57

Calling an exe file from a batch program

#1 Post by simplecode » 14 Jan 2011 11:18

Hello,

I am working on a project which requires execution of a program (in fortran - with no access to the original fortran code being available) currently available only in the form of an exe file. The usual approach towards using this program (say myprog.exe) involves the following steps:

C:\>myprog
Enter the name of the input file:
Enter the name of the output file:
A Boolean Condition (Y/N type):
program executed.

C:\>

Basically, the console waits for the user the enter the appropriate input file name, prints the second line, then waits for the user to enter the output file name, prints the third line, then waits for the user to enter a Y/N type response and executes saving the necessary output file in C drive.

My purpose is to write a batch file which will execute myprog and pass all three parameters simultaneously. Being very new to the MS DOS Batch Language, I tried writing a simple batch file entering the name of the program and all three parameters line by line. But when I try to execute this batch code, it prints the first line ("Enter the name of the input file:") and waits for the user to enter that information. I would appreciate any pointers in the form of sample code or quick reference help documentation that could directly aid in solving the above problem. In the longer run, I hope to run this batch file iteratively with different input files to generate different output files which will then be used by the code I am developing for this project.

Thank you for taking the time to read this post. Please let me know if you need further information.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Calling an exe file from a batch program

#2 Post by aGerman » 14 Jan 2011 12:20

There is no boolean type in batch. Basically all variable values are something like string types. Only SET /A is able to detect/set/calculate numeric values. Maybe you could use 0 for FALSE and 1 for TRUE. Hope your executable will accept this as third argument.

Code: Select all

@echo off &setlocal
:errorloop1
set /p "infile=Enter the name of the input file: "
if not defined infile goto errorloop1

echo/
:errorloop2
set /p "outfile=Enter the name of the output file: "
if not defined infile goto errorloop2

echo/
:errorloop3
set "yesno="
set /p "yesno=A Boolean Condition (Y/N type): "
if /i "%yesno%"=="y" set /a bool=1
if /i "%yesno%"=="n" set /a bool=0
if not defined bool goto errorloop3

start "" "myprog.exe" "%infile%" "%outfile%" %bool%



Regards
aGerman

simplecode
Posts: 2
Joined: 14 Jan 2011 10:57

Re: Calling an exe file from a batch program

#3 Post by simplecode » 14 Jan 2011 13:25

Thank you for your reply. In retrospect, I think I should have provided more information about my problem for which I apologize. Let me explain the problem, again: The way 'myprog.exe' works right now is, as soon as one types 'myprog' on the console, it prints 'Enter an input file name>' and waits for the user to enter a file name. Only after the user has entered the file name does it print another line 'Enter an output file name>' and waits for the user to enter a file name. And so on for the third variable.

My purpose is to find a way to execute myprog.exe without any manual intervention - such that when I execute myprog.exe and it prints 'Enter an input file name>', it doesn't have to wait for the user to enter a file name and can automatically accept the same from some batch file along with the 'enter' key which will lead to the second statement 'Enter an output file name>'. Again it doesn't have to wait for the user to enter a file name and automatically accepts it from the batch file. In essence, I will be using myprog.exe close to a 1000 times and wouldn't want it to print statements and wait for the user to enter values every time. Would there be a way to do so through batch file coding?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Calling an exe file from a batch program

#4 Post by aGerman » 14 Jan 2011 13:45

Batch is not able to emulate the keyboard. If your 'myprog.exe' needs keyboard input and doesn't accept arguments instead then you need a language with a method similar to "SendKeys" in VBScript.

Regards
aGerman

Post Reply