Windows 10

How To Check Batch File Error

In this tutorial, we are going to see how to check batch file error. ERRORLEVEL will contain the return code of the last command. Most commands and programs return 0 on success and some programs return another value. Batch file contains a series of DOS (Disk Operating System) instructions. It allows triggering the execution of commands found in this file.
 

Example 1: How To Check Batch File Error

If the last command returns an error. The ERRORLEVEL variable will contains 1. If there is no error. The ERRORLEVEL variable will contains 0.
 

 

if ERRORLEVEL 1 goto errorHandling
REM no error here, errolevel == 0
:errorHandling

 

Example 2: How To Check Batch File Error
if ERRORLEVEL 1 echo Unsuccessful

If you want to see just the error level run the following command echo %errorlevel%
 

Leave a Reply

Your email address will not be published. Required fields are marked *