From: http://hi.baidu.com/lpf2008007/blog/item/a3fa9a3928bcd9f13a87ce8d.html
If errorlevel
Function:
Test the returned status of the previous program. If the return status of the program is large or equal to the value stated, execute the doscommand
The IF errorlevel command allows the batch processing file to test the return status value of a program, and then perform Further Processing Based on the test results. When
When the MS-DOS encounters an if errorlevel command, it compares the return status value of the previous MS-DOS command with the value described in the IF command, if the return state of the program is greater than or equal to the value stated by the if command, the MS-DOS executes the corresponding command, if the return state value is less than the value described, the MS-DOS continues to execute from the next command in the batch file, and if it uses the if not errorlevel command, the opposite is true.
Example:
The following batch processing file executes the formation command and displays the complete status information of the format-based return value:
@ Echo off
Format:
If errorlevel 5 goto no_response
If errorlevel 4 goto Error
If errorlevel 3 goto user_ctrlc
Echo successful format operation
Goto done
No_response
Echo Fixed Disk will not be formatted
Goto done
: Error
Echo error in processing. Format incopplete
Goto done
: User_ctrlc
Echo format incomplete to ctrl_c
: Done
Note: first, test the maximum returned status value for a batch file. Remember, if the returned status value is greater than or equal to the value described by the if command, the MS-DOS executes the stated command if the batch file first tests whether the returned status value is 3, then the MS-DOS always performs the processing following the user ctrlc brackets, regardless of whether the returned status value is 3. 4. 5. This is because all the returned status values are greater than or equal to 3. After Testing Order is reversed, the batch processing file can execute the correct command group for each returned status value.
By combining if errorlevel and if not errorlevel, you can test a specific returned status value. For example, you can use the following command to test whether the returned status value is 3:
If errorlevel 3 if not errorlevel 4 goto user_ctrlc
5.1.9 test whether the returned status value is smaller than the specified value
Using the not operator in the IF errorlevel command, the batch file will be able to test whether the returned value is smaller than a specific value, if yes, the MS-DOS will execute the stated command: No side, it continues to execute from the next command in the batch processing file. The format of the if not errorlevel command is as follows:
If not errorlevel value doscommand
5.1.10 test specific errorlevel values
When a batch file becomes more complex, you may need to return the status values from 0 to 4 after an if errorlevel command and an if not errorlevel M command.
@ Echo off
Diskcopy A: B:
If errorlevel 0 if not errorlevel 1 echo exit 0
If errorlevel 1 if not errorlevel 2 Echo Exit 1
If errorlevel 2 if not errorlevel 3 Echo Exit 2
If errorlevel 3 if not errorlevel 4 echo exit 3
If errorlevel 4 if not errorlevel 5 echo exit 4
In the first if command. The first test (if errorlevel 0) ensures that the returned status value is at least 0: the second test (if not errorlevel 1) ensures that the returned status value is less than 1. combine the two tests. This command ensures that the returned status value is 0, the class tries, the second if command returns the status value of 1, and so on.