I have an old executable that runs on the command line. It prompts the user interactively for specific pieces of information. What I would like to do is to wrap the all the interaction of this command into a batch script so that it just runs and answers the prompts without a user having to interact.
This is different from simply executing a command with arguments. The executable prompts the user. Paraphrasing the way it works…
C:\MyDir>legacy.exe
Welcome to old program.
Please enter your name:
> John Smith
How many widgets are you buying:
> 47
Great, generating the PO file now...
Goodbye.
Ideally, I would like to actually wait for the prompts and respond to each accordingly. I can do that in .NET with the Process object, but I'd like to attempt this using a windows batch script. If I can't parse the prompts and just need to blindly dump arguments, I'll take that as well.
I see another question where the answer was to use VBScript. Is there a way to do this in plain batch script?
Best Answer
It depends on the way your
legacy.exe
interacts with (redirected) standardinput.You can try this
If that doesn't work you may need a 3rd party
sendkey.exe
and detach legacy.exe from the batch with start as suggested by Genaro Morales and use the sendkey app to do the input in a similar way the vbs solution does. So this isn't pure batch. See these search results.