Skip to content

Instantly share code, notes, and snippets.

@kodybrown
Last active July 15, 2016 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodybrown/7430acd13634c682ae75 to your computer and use it in GitHub Desktop.
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
@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