Last active
July 15, 2016 18:42
-
-
Save kodybrown/7430acd13634c682ae75 to your computer and use it in GitHub Desktop.
Batch file that tests setting a non-zero (error) and a 0 (success) errorlevel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
dir "%temp%" >NUL | |
echo err %errorlevel% | |
dir "c:\doesnotexist" >NUL 2>&1 | |
echo err %errorlevel% | |
dir "%temp%" >NUL | |
echo err %errorlevel% | |
rem https://groups.google.com/forum/m/#!msg/microsoft.public.win2000.cmdprompt.admin/XHeUq8oe2wk/LIEViGNmkK0J | |
rem comment by Ritchie on 7/19/2003 | |
:: apparently it only doesn't reset the errorlevel when calling a `set var=..` | |
dir "c:\doesnotexist" >NUL 2>&1 | |
echo err %errorlevel% | |
set tmpvar=1 | |
echo err %errorlevel% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment