1

I have an old DOS program that I'm running in Windows that has several menus the user can move through by entering numbers (which automatically take you to another menu - no need to press "enter"). At times, the user is required to type in the name of a file then press enter.

I am trying to automate the user's interaction with this program using a batch file. So far, with the help of this resource. I have been sucessful at automating user interaction through menus that only require inputing a number (without pressing enter). However, once the a menue requires typing in a file name and pressing enter, I run into problems.

Here is the code that works in automating the first two menu choices (4, then 6),

(echo 4 
echo 6
) | execute.exe

After pressing 6, the next menu requires typing in a textfile name and pressing enter. However, even the above code (which I would think would stop at the interaction where I need to enter the name of the file) somehow automatically presses enter - meaning the file has no name. This is what is confusing me. Same result if I do something like this:

(echo 4 
echo 6
echo sometext
) | execute.exe

or this:

(echo 4 
echo 6
echo.
) | execute.exe

Inserting PAUSE also does not change anything. Somehow the batch file is treating the menu section that requires entering text and pressing enter in a particular way. Any help appreciated!

Community
  • 1
  • 1
whatIS
  • 57
  • 6
  • `echo.`, `echo,` and `echo:` are all supposed to echo a newline character in a batch file. Have you tried `,` or `:`? Here's an interesting thread: http://stackoverflow.com/questions/132799/how-can-you-echo-a-newline-in-batch-files – James L. Jan 18 '13 at 02:23

1 Answers1

0

Issue

This is how I am imagining the execute.exe program is interpreting the input you are giving it.

echo 4
echo 6

translates into

4
6
_

Underscore '_' is a placeholder for an empty blank line.

Therefore execute.exe waits for the first number, but you are sending echo 4

4
_

So it accepts the first number and then goes to the next number prompt where it ignores the blank enter press as an invalid input and re-prompts for the second number. Send echo 6

6
_

It now accepts the second number for the second prompt and continues onto the file prompt where it is immediately being dismissed by the empty blank line.

Since the program is not expecting the new lines they are being stored as actual command in the input buffer. My best guess is to try outputting only the numbers without a trailing new line caused by the echo command.


Answer

Try this for the number inputs instead of the echo. I have not tried this myself and cannot say if it will work or not. You may also try just doing this with the 6 and still using echo for the 4.

<nul set /p ="4"
<nul set /p ="6"

Note that the set /p command cannot output quotation " or equal = signs as the first/only character. More Info

(
<nul set /p ="4"
<nul set /p ="6"
echo filename
) | execute.exe
David Ruhmann
  • 11,064
  • 4
  • 37
  • 47