0
set /P id=Enter id:
echo %id%

if %id%=='a'
(
:: DO THINGS1
EXIT
)


if %id%=='b'
(
:: DO THINGS2
EXIT
)


else (
echo Input can be either a or b
)

But everytime I am running the file it is not performing any command further even though I am giving 'a' or 'b' as input, it asks for only till user input and exiting. Would appreciate your suggestions

2
  • 2
    Given your example, I would suggest this: 1:@Choice /C ab /M "What is your ID", 2:@If ErrorLevel 2 (Echo=Do things based upon B entry)Else Echo=Do things based upon A entry Commented Sep 23, 2019 at 9:45
  • thanks. I was facing this problem of wrong execution for diffrent string Commented Sep 23, 2019 at 11:44

1 Answer 1

1

Notice how I wrap both values either side of = in double quotes.

@echo off
set /P id=Enter id:
echo %id%

if "%id%"=="a" (
  :: DO THINGS1
  goto :eof
)

if "%id%"=="b" (
   :: DO THINGS2
   goto :eof
 ) else (
   echo Input can be either a or b
)

This typically compares values exactly. i.e something like this.

if "a"=="a"

Would match, because you have the exact either side, where you tried to match this:

if a=='a'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.