views:

21

answers:

2

hello, i want to write a simple batch script, that calls a certain exe, but if this one is not found, it should call another exe.

so in pseudocode

set file=c:\path\tool.exe
if(fileexists(file))
{
    call file
}
else
{
    call c:\somethingelse.exe
}

thanks!

+2  A: 

Perhaps something like this might work?

set FILE=whatever.exe
IF EXIST %FILE% GOTO okay

:notokay
echo NOT FOUND
GOTO end

:okay
echo FOUND
%FILE%

:end
mr.b
+1  A: 

You could use ERRORLEVEL to check if the call executed successfully.

call file.exe
IF ERRORLEVEL 1 other.exe

This will work for executables that are in the path and you don't know the exact location. It will print an error message though.

kgiannakakis
Note that you can also cut that short: `file.exe || other.exe` (and you don't need the `call` there anyway.
Joey