Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
rnara
- Posts: 1
- Joined: 05 Oct 2016 09:53
#1
Post
by rnara » 05 Oct 2016 10:11
Hi,
I have the following code in a bat script. It is always going to the "applied" label even though the numbers are not equal. Please let me know if I'm doing anything wrong. Thanks!
Code: Select all
@echo off
set KNO=3176483
if %KNO% ==3176493 goto applied
:applied
echo #############################
echo Windows Fix Patch is applied
echo #############################
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 05 Oct 2016 11:19
Batch files are sequential processing. It processes line by line. You are not branching away from it executing the code when it is not equal. You need another GOTO for when it is not equal to skip over the :APPLIED code.
-
Cornbeetle
- Posts: 31
- Joined: 23 Nov 2015 09:34
#3
Post
by Cornbeetle » 05 Oct 2016 14:02
Like Squash said, try this:
Code: Select all
@echo off
set KNO=3176483
if %KNO% ==3176493 (
echo #############################
echo Windows Fix Patch is applied
echo #############################
) else (
goto:continue
)
pause
:continue
echo Numbers are not equal
pause
-
Compo
- Posts: 600
- Joined: 21 Mar 2014 08:50
#4
Post
by Compo » 05 Oct 2016 20:18
Here's some ideas for you.
either:
Code: Select all
@Echo Off
Set KNO=3176483
If %KNO%==3176493 GoTo :Applied
GoTo: NotApplied
:Applied
Echo=#############################
Echo=Windows Fix Patch is applied
Echo=#############################
GoTo :AnotherLabel
:NotApplied
REM more code here
or:
Code: Select all
@Echo Off
Set KNO=3176483
If Not %KNO%==3176493 GoTo :NotApplied
:Applied
Echo=#############################
Echo=Windows Fix Patch is applied
Echo=#############################
:NotApplied
REM more code here
or:
Code: Select all
@Echo Off
Set KNO=3176483
If %KNO%==3176493 Call :Applied
REM more code here
Exit/B
:Applied
Echo=#############################
Echo=Windows Fix Patch is applied
Echo=#############################
GoTo :EOF