Windows batch file if else usage

Sorry I am new to this stuff. I'd like to run in a certain sequence the same bat file with different parameters. I wrote a very simple batch file:

@echo off

REM Note: to see all command line usage options, run bsearch_headless.bat without any arguments.

call behaviorsearch_headless.bat -p test_behaviorsearch.bsearch -o pippo

ECHO
IF EXIST pippo.finalBests.csv (call behaviorsearch_headless.bat -p test_behaviorsearch.bsearch -o topolino)
else goto :eof  

:eof
ECHO Simulatione End!
PAUSE

It does not work because else is not recognized.

Many thanks for any help!


From the if documentation on the command line (via help if or available in TechNet too).

The ELSE clause must occur on the same line as the command after the IF. For example:

IF EXIST filename. (
    del filename.
) ELSE (
    echo filename. missing.
)

The following would NOT work because the del command needs to be terminated by a newline:

IF EXIST filename. del filename. ELSE echo filename. missing

Nor would the following work, since the ELSE command must be on the same line as the end of the IF command:

IF EXIST filename. del filename.
ELSE echo filename. missing


So, your script would work if you replaced

IF EXIST pippo.finalBests.csv (call behaviorsearch_headless.bat -p test_behaviorsearch.bsearch -o topolino)
else goto :eof 

With

IF EXIST pippo.finalBests.csv (call behaviorsearch_headless.bat -p test_behaviorsearch.bsearch -o topolino) else goto :eof

OR

IF EXIST pippo.finalBests.csv (
    call behaviorsearch_headless.bat -p test_behaviorsearch.bsearch -o topolino
) else (
    goto :eof
)

Hope that helps.