%errorlevel% doesn't work in WindowsXP.
As I know when an error occurs %errorlevel% set 1 or above value, and if there is no error it will set 0.
But, even though there is no error, %errorlevel% is 1. And I set %errorlevel% 0, even there is an error %errorlevel% is sill 0.
I think OS doesn't change %errorlevel% in XP.
In Win7 it work totally.
@echo off
setlocal enabledelayedexpansion
call dir
echo errorlevel=%errorlevel%
REM expected errorlevel=0 but 1
call dor
echo errorlevel=%errorlevel%
REM expected errorlevel=1
set errorlevel=0
call dor
echo errorlevel=%errorlevel%
REM expected errorlevel=1 but 0
But if errorlevel 1 () looks work.
some examples for you:
output:
output:
output:
set errorlevel
is not a legal command. If you need to set the errorlevel system environment variable, do this with a usual command.output: