JSI Tip 6394. How can I test if a batch command failed or succeeded?

Jerold Schulman

March 2, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today

I introduced conditional processing symbols in tip 0290:

The double ampersand (&&) causes the command following this symbol to run only if the command preceding the symbol is successful.

The double pipe (||) causes the command following this symbol to run only if the command preceding the symbol fails.

Examples

pushd \ServerNameShareName||goto NoAccess

If the command fails, goto NoAccess will be executed.

pushd \ServerNameShareName&&goto popit
@echo The user has no access
goto :EOF
:popit
REM Do stuff while the current folder is \ServerNameShareName
popd

If the command is successful, goto popit is executed, otherwise the error is echoed.



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like