How to read console input in a batch file?

How to read console input in a batch file? What I'm trying to achieve is the scanf function in C. How can I do the same in a batch file?

+54
windows cmd batch-file
Oct 24 2018-11-18T00:
source share
3 answers

The code snippet in the connected duplicate reads user input.

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

The user can enter as many letters as he wants, and he will enter the delBuild variable.

+91
Oct 24 '11 at 18:43
source share

As everyone says, just use set /p varname="prompt message" . If you just want to quickly open a cmd instance instead of exiting immediately, just do the following:

 set /p temp="Hit enter to continue" 

at the end of your script and it will open a window.

+9
Mar 20 '15 at 2:47
source share

In addition to the existing answer, you can set the default parameter as follows:

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

This allows users to simply press β€œEnter” if they want to enter a default value.

+8
Mar 04 '15 at 12:20
source share



All Articles