Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming

Get user input from DOS prompt

0.00/5 (No votes)
8 Jan 2011CPOL 7.6K  
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%...
)

License

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