我希望你是我独家记忆

一段永远封存的记忆,随风而去
posts - 263, comments - 31, trackbacks - 0, articles - 3
   :: 首页 :: 新随笔 ::  :: 聚合  :: 管理

Taking User Input at DOS Prompt

Posted on 2010-11-25 09:31 Hero 阅读(386) 评论(0)  编辑 收藏 引用 所属分类: DOS

 

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)
 Collapse 
| Copy Code
SET 
/<var>=[<prompt message>]

Example
 Collapse 
| Copy Code
@ECHO OFFSET 
/P uname=Please enter your name: 
IF 
"%uname%"=="" GOTO Error
ECHO Hello 
%uname%, Welcome to DOS inputs!
GOTO End
:Error
ECHO You did not enter your name
! Bye bye!!
:End

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.



只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理