Batch Script – Input / Output
In this article, we are going to learn how to take input from users using Batch Script.
Taking User Input:
@echo off echo Batch Script to take input. set /p input= Type any input echo Input is: %input% pause
- The first ‘echo’ command is used to print a string.
- In the next line, ‘set /p’ command is used to take user input followed by a variable that will hold user input.
set /p input= Type any input
- Then for printing the user input we will use ‘%’ on both ends of our variable which is used for holding user input in the previous step.
echo Input is : %input%
- ‘ pause ‘ is used to hold the screen until any key is pressed.
Input Code :
Execution of the above code :
1. After saving the above code with .bat format. When we will run the file, the below cmd screen will be shown.
2. In the next step we will provide any input, as shown.
3. After pressing enter we will get user input data as Output, as shown in the below image.