Click here to Skip to main content
13,556,447 members
Click here to Skip to main content
Add your own
alternative version

Tagged as



5 bookmarked
Posted 2 Nov 2010
Licenced CPOL

Get user input from DOS prompt

, 13 Nov 2010
Rate this:
Please Sign up or sign in to vote.
Command Line Inputs


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 GOTO and Labels to control the flow.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

India India
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.

You may also be interested in...

Comments and Discussions

QuestionMy Vote of 5 Pin
David A. Gray13-Nov-17 22:12
memberDavid A. Gray13-Nov-17 22:12 
GeneralReason for my vote of 5 quick answer, some time when working... Pin
dennislx7-Dec-11 18:44
memberdennislx7-Dec-11 18:44 
GeneralReason for my vote of 4 Help me, good job! Pin
dennislx7-Sep-11 7:34
memberdennislx7-Sep-11 7:34 
GeneralJust to add to it... The page &lt;a href=" Pin
GuruprasadV28-Dec-10 17:35
memberGuruprasadV28-Dec-10 17:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180515.1 | Last Updated 13 Nov 2010
Article Copyright 2010 by mravikiran
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid