Dean Wells said:
It appears to require 3 components (at least that I've found so far) in
order to trigger the behavioral difference -
1. Use of a call statement
2. An error of some kind
3. an environment modification
It's simply that a .cmd file using the SET command to assign a value to
a variable, results in the errorlevel being cleared (set to zero). Doing
the same in a .bat file does not change the errorlevel. See this batch
file, and the output below for an example:-
------------ a.bat/a.cmd starts below ------------------
@echo off & setlocal ENABLEEXTENSIONS
ver>nul
echo/After the VER command, errorlevel is %errorlevel%
md;2>nul
echo/Using MD incorrectly, errorlevel is %errorlevel%
set var=1
echo/After setting var, errorlevel is %errorlevel%
------------ a.bat/a.cmd ends above --------------------
<SCREEN SHOT>
d:\data\bat\help>a.cmd
After the VER command, errorlevel is 0
Using MD incorrectly, errorlevel is 1
After setting var, errorlevel is 0
d:\data\bat\help>a.bat
After the VER command, errorlevel is 0
Using MD incorrectly, errorlevel is 1
After setting var, errorlevel is 1
<\SCREEN SHOT>