I have a command-line program that normally gets its parameters from the keyboard after the program is run. Something like this:
Enter parameter 1? 3
Enter parameter 2? 2.6
Calculate something y/n? y
Rewriting the program to take command-line parameters is not possible.
I'd like to time how long it takes to execute the program with a batch file that is similar to the following:
@echo %time%
program.exe < params.txt
@echo %time%
The problem is that for some reason, the final parameter does not get accepted.
Note that the final parameter is a y/n, and I have added an empty line at the end so there is a newline after the y/n.
The input file, params.txt
:
3
2.6
y
*empty line*
Best Answer
You can automate interactive command line programs using
expect
Here's an example (for telnet) from the Wikipedia article
It should be clear that you can use this approach for your program as you know the prompt strings and you know what responses to feed it.