some examples for you:
@ECHO OFF &SETLOCAL
echo errorlevel=%errorlevel%
call dir >nul
echo errorlevel=%errorlevel%
output:
errorlevel=0
errorlevel=0
@ECHO OFF &SETLOCAL
echo errorlevel=%errorlevel%
call dor
echo errorlevel=%errorlevel%
output:
errorlevel=0
'dor' is not recognized as an internal or external command,
operable program or batch file.
errorlevel=1
@ECHO OFF &SETLOCAL
::set errorlevel=0 illegal operation!
set test=1
set test
echo errorlevel=%errorlevel%
call dor
echo errorlevel=%errorlevel%
output:
test=1
errorlevel=0
'dor' is not recognized as an internal or external command,
operable program or batch file.
errorlevel=1
set errorlevel
is not a legal command. If you need to set the errorlevel system environment variable, do this with a usual command.
@ECHO OFF &SETLOCAL
::set errorlevel=1 illegal operation!
set test
echo errorlevel=%errorlevel%
call dir >nul
echo errorlevel=%errorlevel%
output:
Environment variable test not defined
errorlevel=1
errorlevel=0