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

Echo You entered one!
GOTO endingsection

Echo You entered two!

Echo You did not enter three!


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

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

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
(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