If receives x, goto :x?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Draginz
Posts: 7
Joined: 07 Jul 2010 00:53

If receives x, goto :x?

#1 Post by Draginz » 08 Jul 2010 01:10

Is there a command like this? Where if, the batch requests some text, and if it matches the text it requested, then it proceeds?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: If receives x, goto :x?

#2 Post by aGerman » 08 Jul 2010 11:02

Seems you have to learn the basics.
Have a lokk to the Command Index.

Of course, there is a way to compare an user input.

Code: Select all

@echo off &setlocal
set /p "input=Enter a or b: "
if /i "%input%"=="a" goto a
if /i "%input%"=="b" goto b
goto c

:a
echo you entered an "a"
goto :end

:b
echo you entered an "b"
goto :end

:c
echo you entered neither "a" nor "b""

:end
echo.
pause


Or not that "Spaghetti-Code-Like"

Code: Select all

@echo off &setlocal
set /p "input=Enter a or b: "
if /i "%input%"=="a" (call :a) else (
  if /i "%input%"=="b" (call :b) else call :c
)
echo.
pause
goto :eof

:a
echo you entered an "a"
goto :eof

:b
echo you entered an "b"
goto :eof

:c
echo you entered neither "a" nor "b""
goto :eof



Regards
aGerman

Draginz
Posts: 7
Joined: 07 Jul 2010 00:53

Re: If receives x, goto :x?

#3 Post by Draginz » 08 Jul 2010 14:15

Thank you for that command index link, it's very helpful. I was looking for something like that on the site.
But can I have it so that the input has more than one letter in it? That's what I was looking for.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: If receives x, goto :x?

#4 Post by aGerman » 08 Jul 2010 14:30

It's exactly the same.

Just pay attention that a label will be valid until the first space.
:abc 1 is the same like :abc 2.

Regards
aGerman

Draginz
Posts: 7
Joined: 07 Jul 2010 00:53

Re: If receives x, goto :x?

#5 Post by Draginz » 08 Jul 2010 14:49

Ah, okay, thank you very much, that's very helpful!

Draginz
Posts: 7
Joined: 07 Jul 2010 00:53

Re: If receives x, goto :x?

#6 Post by Draginz » 08 Jul 2010 14:59

Oh yeah, and one more thing:
Can I hide the 'enter a or b' text?
Edit:
Nevermind, I found out how!

Post Reply