Creating Batch Script with User Input

Batch Script supports the concept of command line arguments where arguments can be passed to a batch file when called.

Using the /p switch and the SET command, you can define variables from an Input.

/p switch allows you to set the value of a variable to the input line entered by the user.

The following script is an example of getting input from the user using the keyboard.

@echo off
echo Enter your variable : 
set /p variable=
echo Your variable is %variable%

The result of the script

input01

You can simplify the script to .

@echo off
SET /P variable=Enter your variable :
echo Your variable is %variable%

Result

input02

Latest Articles