A lot of times, when we write batch files (*.bat) or command files (*.cmd), we would want to take user input at the DOS prompt during runtime of the script. This article explains how to fulfill that need.
Taking User Input at DOS Prompt
It is a very simple way to get the user input at the DOS prompt. You need to use the
SET command with a variable name for this purpose.
SET Command (syntax)
SET /P <var>=[<prompt message>]
SET /P uname=Please enter your name:
IF "%uname%"=="" GOTO Error
ECHO Hello %uname%, Welcome to DOS inputs!
ECHO You did not enter your name! Bye bye!!
Points of Interest
The word "
uname" in the above script is the variable that captures the user input. The above script also shows the validation whether any input is given or not. Use
Labels to control the flow.
Ravikiran Malladi is a senior software professional in Microsoft technologies. He has global IT experience of over 10 years and has compulsive habit of writing tools, particularly for the projects he works on. He has vast experience in the roles of senior developer, technical analyst, technical architect besides in technical lead roles.
His hobbies include chess, music, cricket, web sites along side writing technical articles and technical blogs.