Open In App

Batch Script – Input / Output

Improve
Improve
Like Article
Like
Save
Share
Report

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

Explanation :

  • 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 :

code for taking user input

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.

After running the file

2. In the next step we will provide any input, as shown.

Giving input as Geeks For Geeks

3. After pressing enter we will get user input data as Output, as shown in the below image.

Final Output is displayed


Last Updated : 28 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads