(How) can a program with interactive command line mode (shell) be programmatically "interacted" with from CMD.exe via batch file (.bat)? Example:


The batch file should start program.exe, send aCommand, then [optionally] wait for someResponse and so on.

There's How to interact with command-line program using batch file? but does not need automated interaction and so accepts CALL as answer.

Maybe it's possible to start the process separately and then pipe commands and responses to communicate with it?



Various mechanisms exist for .bat files, although very limited.

Microsoft DOS set command

Syntax : SET /P variable=[promptString]

Example :

ECHO 1. Print Hello
ECHO 2. Print Bye
ECHO 3. Print Test
set choice=
set /p choice=Type the number to print text.

Microsoft DOS choice command

Syntax : CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]

Example :

CHOICE /C YNC /M "Press Y for Yes, N for No or C for Cancel."

Pause command

Syntax : pause

Issues the message "Press any key to continue . . ." and waits for any key.

| improve this answer | |
  • While that does not answer my question, it's very good to know! :-) choice works similarly to set /p but sets errorlevel. Here's another CMD reference: ss64.com/nt/choice.html – handle Oct 28 '18 at 9:15
  • What would answer your question? – harrymc Oct 28 '18 at 9:40
  • :-) If I knew, there would be no question. – handle Oct 28 '18 at 9:44
  • These are the commands I do know. If you are looking for more sophistication, you will need to write a program that returns a number to the script via errorlevel. – harrymc Oct 28 '18 at 9:49
  • I appreciate your effort but we seem to not understand each other. I've added to my question, hoping to make it clearer. Your answer does not seem to cover any communication with a separate program. – handle Oct 28 '18 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.