Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read input from console in a batch file?

How do I read input from the console in a batch file? What I am trying to achieve is the functionality of scanf in C. How can I do the same in a batch file?

like image 833
Nohsib Avatar asked Oct 24 '11 18:10

Nohsib


People also ask

How do you automate input in command prompt?

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.

How do I pass a command line argument to a batch file?

In the batch script, you can get the value of any argument using a % followed by its numerical position on the command line. The first item passed is always %1 the second item is always %2 and so on. If you require all arguments, then you can simply use %* in a batch script.

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.


1 Answers

The code snippet in the linked proposed duplicate reads user input.

ECHO A current build of Test Harness exists. set /p delBuild=Delete preexisting build [y/n]?:  

The user can type as many letters as they want, and it will go into the delBuild variable.

like image 132
Raymond Chen Avatar answered Sep 28 '22 12:09

Raymond Chen