priyanka.sarkar
priyanka.sarkar

Reputation: 26498

Could not compare a value in Batch file

What is wrong with the below syntax:

    @ECHO OFF

SET FLAG=TRUE

invalidcmd
call :checkERR "Duplicate Entry " 
@ECHO %FLAG%
IF "%FLAG%" EQU  "TRUE"(
    @ECHO DONEXT
) 
ELSE (
@ECHO INVALID

)

:checkerr
    REM echo %ERRORLEVEL% with %1
    IF NOT %ERRORLEVEL% == 0 (
        @ECHO %1
        SET FLAG=FALSE
        REM EXIT /B %ERRORLEVEL%
        )

Objective is if the %FLAG% is FALSE then it must echo INVALID.

But I am getting the below output:

D:\ >installer.bat [hidden arguments]
'invalidcmd' is not recognized as an internal or external command, operable program or batch file.
"Duplicate Entry "
FALSE
The syntax of the command is incorrect.

Upvotes: 0

Views: 27

Answers (1)

Magoo
Magoo

Reputation: 80023

  1. There must be a separator before the opening parenthesis of the IF true-condition target
  2. That opening parenthesis must be on the same physical line as the if
  3. Where an 'else' clause is used, the ending parenthesis of the "true" block, a separator and the else keyword must be on the same physical line
  4. Where an 'else' block is used, the else keyword, a separator and the opening parenthesis of the "else" block must be on the same physical line

ie

if condition (
 something
) else (
 someotherthing
)

Upvotes: 1

Related Questions