Your problem is not that this level of error requires special treatment, it is not like a normal environment variable. The only test you can do with the error level is to check if it is greater than or equal to the value.
so you need to check the error level values ββfrom the highest to the lowest, because if the error level is 1 then if errorlevel 1 will be true, but if errorlevel 0 will also be true
setlocal set /A sample =1 :first type C:\test.txt | find "inserted" if errorlevel 1 goto exam if errorlevel 0 goto test :test echo "testloop" >> C:\testloop.txt set /A sample = %sample% + 1 if %sample% LEQ 4 goto first :exam echo "exam loop" >> C:\examloop.txt endlocal
if you have command extensions activated and there is no environment variable called ERRORLEVEL (case insensitive). Then, in theory, you can use% ERRORLEVEL% as a normal environment variable. So this should also work.
setlocal EnableExtensions set /A sample =1 :first type C:\test.txt | find "inserted" if %errorlevel% EQU 1 goto exam if %errorlevel% EQU 0 goto test :test echo "testloop" >> C:\testloop.txt set /A sample = %sample% + 1 if %sample% LEQ 4 goto first :exam echo "exam loop" >> C:\examloop.txt
John knoeller
source share