Click here to Skip to main content
15,885,914 members
Articles / General Programming
Alternative
Tip/Trick

Get user input from DOS prompt

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Jan 2011CPOL 7.5K   1  
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)


Written By
Validity Sensors, Inc.
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --