Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically answer to input prompt in windows batch

In a windows batch, I want to start a program that prompts the user for an input:

>someProgram.exe > "Please enter "s" to start the program: >  

How can I automatically pass the "y" input to the prompt, such that I can start the program by just clicking the batch?

like image 243
user1934212 Avatar asked Nov 15 '16 12:11

user1934212


People also ask

Can a batch file prompt for input?

You are able to prompt a user for input using a Batch script function.

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

What is %1 in a batch file?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.

What is %% A in batch script?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


2 Answers

You want this:

echo y | [Command] 

Eg: echo y | program.exe

"echo <answer> | <batch command>" 

Ex: The del /P command option will prompt for user's confirmation before deleting the file. So if you are using this option in your batch script, it requires manual input to proceed further. To avoid this manual input, use the command "echo Y | del /P " in your batch script to answer the prompt.

You can try this echo command to pass input (ex: answer for username and password prompts) to your console application, when it is invoked through batch script.

Refer: http://thirutechie.blogspot.com/2009/10/how-to-auto-answer-prompts-in-windows.html

like image 114
Chandana Kumara Avatar answered Oct 11 '22 20:10

Chandana Kumara


For multiple inputs, do:

(echo input1 && echo input2) | program.exe

like image 26
ImagineMBE Avatar answered Oct 11 '22 19:10

ImagineMBE