Call vs Start

For exe files, I suppose the differences are nearly unimportant.
But to start an exe you don’t even need CALL.

When starting another batch it’s a big difference,
as CALL will start it in the same window and the called batch has access to the same variable context.
So it can also change variables which affects the caller.

START will create a new cmd.exe for the called batch and without /b it will open a new window.
As it’s a new context, variables can’t be shared.

Using CALL can change the parameters (for batch and exe files), but only when they contain carets or percent signs.

call myProg param1 param^^2 "param^3" %%path%%

Will be expanded to (from within an batch file)

myProg param1 param2 param^^3 

Delayed Expansion

You found the bbb (batch beginner bug), but not the variable is empty, it’s the expansion that doesn’t work as expected.

Percent expansion is done when a line or a complete parenthesis block is parsed, before the code will be executed.
But to solve this you can use the delayed expansion, this doesn’t expand at parse time, it expands just at execution time.

setlocal EnableDelayedExpansion

if exist "%_REALPATH%\tomcat-%TOMCAT_VER2%" (
echo "!TOMCAT_VER!"
) else if exist "%TOMCAT_VER2%" (
echo "!TOMCAT_VER!"

Using Windows PowerShell to run old command line tools (and their weirdest parameters)


Problem 1: Name conflicts

Solution 1A: Use the .EXE extension

Solution 1B: Use CMD /C

Solution 1C: Use a PowerShell equivalent

Problem 2: Special PowerShell characters

Solution 2A: Use CMD /C

Solution 2B: Use the PowerShell escape character


IF ERRORLEVEL is a special syntax supported since the DOS days, the %ERRORLEVEL% variable support was added in WinNT.

The original syntax is used like this:

call someapp.exe
if errorlevel 1 goto handleerror1orhigher
if errorlevel 0 echo succuess...

To use the variable, use the normal IF syntax: if %errorlevel%==0 echo success...

Note that %errorlevel% stops working if someone does set errorlevel=foo and it might not get updated for internal cmd.exe commands.

An alternative solution is to use &&:

call someapp.exe && (echo success) || (echo error!)