0

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?

Angelo
  • 1,073

2 Answers2

1

It depends on the way your legacy.exe interacts with (redirected) standardinput.

You can try this

(Echo John Smith&Echo 47)|legacy.exe

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.

LotPings
  • 7,231
  • Thanks, it appears that in my particular case I can't use "echo" to feed input to my commandline executable. Will need to investigate sendkey and vbscript solutions. – Angelo Jun 26 '17 at 14:58
  • Turns out that vbscript + wsh (windows script host) w/sendkeys is the lowest friction way to do this. – Angelo Jun 27 '17 at 12:06
-1

Have you ever tried to get a batch file with:

start "fullpath" legacy.exe ?

  • No... can you elaborate? Doesn't start simply open a new command window and execute the given command. – Angelo Jun 23 '17 at 19:44
  • the start instruction opens a new command window and runs the exe or the batch file you put on the arguments (running as start /B runs the exe in the same command window opened by the batch), I'm not pretty sure if you only want to run the program from a batch file or if you are attempting to get the same behaviour that the exe has in the batch script – Genaro Morales Jun 23 '17 at 20:07
  • @Genaro Morales why don't you edit your answer and write the information needed in order to elaborate your answer – yass Jun 23 '17 at 20:51