65.9K
CodeProject is changing. Read more.
Home

Get user input from DOS prompt

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Jan 8, 2011

CPOL
viewsIcon

7604

Not quite, CDMTJX. There are 2 problems with the alternative you posted.Previous values for uname are not cleared. Running this twice WILL see the previous valueThe logic is backwards.This will work as you intended:@ECHO OFFset uname=SET /P uname="Please enter your name: "IF...

Not quite, CDMTJX. There are 2 problems with the alternative you posted.
  1. Previous values for uname are not cleared. Running this twice WILL see the previous value
  2. The logic is backwards.
This will work as you intended:
@ECHO OFF
set uname=
SET /P uname="Please enter your name: "
IF "%uname%"=="" (
  ECHO error ...
 ) ELSE (
  ECHO Hello %uname%...
)