Input used in IF command in a .bat

February 21, 2010 at 07:45:53
Specs: Windows 7
Hey, I'm new to batch files and have been
asked as part of my assignment to develop a
.bat that reads user input and uses that in an if
statement. It's starting to really bug me...
@echo off

set /p %number =

set %one =1
set %two =2
set %three =3

IF [%number%] == [%three%] GOTO END

IF NOT [%number%] == [%one%] GOTO numbertwo

:numberone
Echo You entered one!
GOTO endingsection

:numbertwo
Echo You entered two!

:endingsection
Echo You did not enter three!

:END


Its basically if the user inserts 1 or 2, then
print the message "you inserted one" or "you
inserted two", and in both cases "it wasn't a
three"


See More: Input used in IF command in a .bat

Report •

#1
February 21, 2010 at 13:31:06
Baby, you are in the wrong Forum!

Batch is NOT DOS, almost batch under Windows 7 you have to code. The SET /P statement is supported under NT batch only NOT under plain DOS. There is no DOS in Windows 7 that is a NT kernel system.

So stated your script is horrible and shows how much you have to learn about the principles of batch scripting.

Anyway see the following sample and try to learn something...

@echo off & setlocal
:LOOP
cls
(set ans=)
set /P num=Enter 1, 2 or 3^>

if  "%num%"=="1" set ans=one
if  "%num%"=="2" set ans=two
if  "%num%"=="3" goto :EOF
if not defined ans goto :LOOP

echo.  You inserted %ans%
echo.  It was not three.
:: End_Of_Batch


Report •
Related Solutions


Ask Question