Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Batch Script – Input / Output

  • Last Updated : 28 Nov, 2021

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%

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!