Computing.Net > Forums > Programming > IF ELSE Error in Batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

IF ELSE Error in Batch file

Reply to Message Icon

Name: arun_s010
Date: June 12, 2007 at 22:57:03 Pacific
OS: Windows 2003 Server
CPU/Ram: 1GB
Product: DELL
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 13, 2007 at 03:09:21 Pacific
Reply:

@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.


0
Reply to Message Icon

Related Posts

See More


Ping Config - blog Array/Dictionary/Somethin...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: IF ELSE Error in Batch file

If else statement in Batch file www.computing.net/answers/programming/if-else-statement-in-batch-file/16954.html

Error level in batch file www.computing.net/answers/programming/error-level-in-batch-file/16461.html

Date Routines in Batch Files www.computing.net/answers/programming/date-routines-in-batch-files/15590.html