10

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!

2
  • Obviously, if is not the problem you are asking about, but doesn’t the ECHO in the middle of your batch file need to be ECHO. or something? Mar 15, 2013 at 23:41
  • Have I answered your question?
    – BDM
    Mar 17, 2013 at 5:11

2 Answers 2

21

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.

0

ifelf.cmd:

@ECHO OFF
@IF EXIST "C:\boot.ini" (
@ECHO WoW! It may be M$Windows! 
) ELSE (
@ECHO Boot.ini Lost! My precious! Stolen! 
)
@ECHO .
@ECHO Wait 10 sec ...
@ping 127.0.0.1 -n 10 > NUL
5
  • 1
    What's with all the @s?
    – BDM
    Mar 15, 2013 at 23:37
  • @ProfPickle Hides map commands. Sample @ECHO OFF and ECHO OFF.
    – STTR
    Mar 15, 2013 at 23:49
  • 2
    I know, but you don't need to use it once you put echo off.
    – BDM
    Mar 15, 2013 at 23:56
  • 1
    @ProfPickle Yes, it is, but there have been times and programs ignore ECHO OFF but perceiving @. Think of it as a tribute to my paranoia or historical cases).
    – STTR
    Mar 16, 2013 at 0:02
  • 2
    Fair enough, I understand paranoia.
    – BDM
    Mar 16, 2013 at 0:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .