How do I get the application exit code from a Windows command line?

A pseudo environment variable named errorlevel stores the exit code: echo Exit Code is %errorlevel% Also, the if command has a special syntax: if errorlevel See if /? for details. Example @echo off my_nify_exe.exe if errorlevel 1 ( echo Failure Reason Given is %errorlevel% exit /b %errorlevel% ) Warning: If you set an environment variable … Read more

Batch command date and time in file name

Another solution: for /f “tokens=2 delims==” %%I in (‘wmic os get localdatetime /format:list’) do set datetime=%%I It will give you (independent of locale settings!): 20130802203023.304000+120 ( YYYYMMDDhhmmss.<milliseconds><always 000>+/-<minutes difference to UTC> ) From here, it is easy: set datetime=%datetime:~0,8%-%datetime:~8,6% 20130802-203023 For Logan’s request for the same outputformat for the “date-time modified” of a file: for … Read more

How to have multiple colors in a Windows batch file?

You can do multicolor outputs without any external programs. @echo off SETLOCAL EnableDelayedExpansion for /F “tokens=1,2 delims=#” %%a in (‘”prompt #$H#$E# & echo on & for %%b in (1) do rem”‘) do ( set “DEL=%%a” ) echo say the name of the colors, don’t read call :ColorText 0a “blue” call :ColorText 0C “green” call :ColorText … Read more