Solved IF ELSE Error in Batch file

DELL
June 12, 2007 at 22:57:03
Specs: Windows 2003 Server, 1GB
Hi,

I am writing a batch file. I am accepting the parameter from user and trying to display message depending on the parameter entered. Here is the batch file content

@ECHO OFF

SET /P USERPARM=Enter the Value :

IF "%USERPARM%"==""
ECHO Nothing is entered
ELSE IF "%USERPARM"=="Y"
ECHO Success
ELSE IF "USERPARM"=="N"
ECHO Failure.
ENDIF

But when user enters value instead of displying message command prompt is getting closed. Please let me know if this code has any errors. I am new to batch programming.


Thanks
Arun S


See More: IF ELSE Error in Batch file

Report •


#1
June 13, 2007 at 03:09:21
✔ Best Answer
@ECHO OFF
:LOOP
SET /P USERPARM=Enter the Value :

IF "%USERPARM%"=="" (
ECHO Nothing is entered
GoTo :LOOP
)
IF /I "%USERPARM%"=="Y" (
ECHO Success
) ELSE (
IF /I "%USERPARM%"=="N" (
ECHO Failure
) ELSE (
ECHO The param entered is not Y/y nor N/n
)
)
:: End_Of_Batch

Notes:

- Avoid nested IF as they become unreadable.
- Use IF /I to avoid upper/lowercase difference.
- ENDIF is not a batch statement.


Report •
Related Solutions


Ask Question