Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
    
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? –  Scott Mar 15 '13 at 23:41
    
Have I answered your question? –  Prof Pickle Mar 17 '13 at 5:11
add comment

2 Answers

From the if documentation on the command line.

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.

share|improve this answer
add comment

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
share|improve this answer
1  
What's with all the @s? –  Prof Pickle Mar 15 '13 at 23:37
    
@ProfPickle Hides map commands. Sample @ECHO OFF and ECHO OFF. –  STTR Mar 15 '13 at 23:49
1  
I know, but you don't need to use it once you put echo off. –  Prof Pickle Mar 15 '13 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 '13 at 0:02
1  
Fair enough, I understand paranoia. –  Prof Pickle Mar 16 '13 at 0:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.