How to get exit code from command prompt?
Posted: 09 Sep 2016 07:47
How do I get the exit code of a command with runret?
runret returns the standard output only. So I thought of echoing %errorlevel% to stdout, but this doesn't work:Both return errorlevel as 0 even though the second one should fail.
I know about exit-code based conditional running with && and ||, but this still doesn't give me the actual exitcode.No help when the exit code is something other than 0 and 1.
runret returns the standard output only. So I thought of echoing %errorlevel% to stdout, but this doesn't work:
Code: Select all
::echo runret("%COMSPEC% /c reg QUERY HKCU\Environment /ve & echo %errorlevel%", "%WINDIR%\system32\");
::echo runret("%COMSPEC% /c reg QUERY HKCU\Environment /v NONEXISTENT_VALUE & echo %errorlevel%", "%WINDIR%\system32\");I know about exit-code based conditional running with && and ||, but this still doesn't give me the actual exitcode.
Code: Select all
::echo runret("%COMSPEC% /c reg QUERY HKCU\Environment /ve && echo success || echo fail", "%WINDIR%\system32\");
::echo runret("%COMSPEC% /c reg QUERY HKCU\Environment /v NONEXISTENT_VALUE && echo success || echo fail", "%WINDIR%\system32\");