Creating Batch Script with User Input

bardimin pic

Written by Bardimin

On May 29, 2022
Home » Blogs » Windows » Creating Batch Script with User Input

Batch Script supports the concept of 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 is an example of getting input from the user using the .

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

The result of the

input01

You can simplify the script to .

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

Result

input02

Latest Articles

The sequence of Windows boot processes from zero to ready

The sequence of Windows boot processes from zero to ready

Have you ever wondered how exactly the Windows boot process happens? What processes happen in the background when you press the power button until Windows is ready for you? If yes, then you are in the right place. In this article, Bardimin will explain how all these...

Redirect and Block URLs with HOSTS File on Windows

Redirect and Block URLs with HOSTS File on Windows

Redirect and Block URLs you can easily on Windows. Just by adding the IP of a website, you can redirect or block it. Of course, this is very useful to limit the access of your employees or children from accessing websites that you do not allow. Your Windows PC has...

How to Create Fake Files of Any Size in Windows

How to Create Fake Files of Any Size in Windows

Do you need a file with a size of 10 MB, 100 MB, 1 GB or 1 TB to test? Follow the following article to create one instantly. You don't need to download files or waste time searching for large files, you can create them easily. Sometimes you need large files quickly to...

10 Causes of Windows PC crashes you should know

10 Causes of Windows PC crashes you should know

A fatal error will cause the system to become unstable or busy. Your Windows PC will often display the Blue Screen of Death (BSOD). Do you experience it often? A computer that often crashes is quite annoying for all users, especially when you are doing important work...