About the if errorlevel command

Source: Internet
Author: User

Reference: http://hi.baidu.com/lpf2008007/blog/item/a3fa9a3928bcd9f13a87ce8d.html

1. If errorlevel tests the return status of the previous program, if the return status of the program is large or equal to the value described, execute the doscommand if errorlevel command to test the return status value of a program in the batch file, then, based on the test results, 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 executing from the next command in the batch file if
The not errorlevel command is the opposite: the following batch processing file executes the formation command and displays the complete status information of the format-based Return Value: @ echo offformat: if errorlevel 5 goto no_responseif errorlevel 4 goto errorif errorlevel 3 goto specify successful format operationgoto doneno_responseecho Fixed Disk will not be formattedgoto done: errorecho error in processing. format incoppletegoto done: user_ctrlcecho format incomplete to ctrl_c: Done batch file first test the maximum returned status value. 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, the MS-DOS always executes "Goto user ctrlc", regardless of whether the returned status value is 3, 4, or 5. This is because all the returned status values are greater than or equal to 3 and the test order is reversed, the batch processing file can execute the correct command group for each returned status value, and test a specific returned status value by combining if errorlevel and if not errorlevel. 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 note: In this case, it is best to use if % errorlevel % = 3 goto user_ctrlc 2, if not errorlevel tests the return status of the previous program. If the return status of the program is less than the value described, execute the doscommand to use the not operator for 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 will continue to execute from the next command in the batch file, the format of the if not errorlevel command is as follows: if not errorlevel value doscommand 3 tests the specific errorlevel value. When a batch file becomes more complex, you may need to run an if errorlevel command with an if not error Return status value from 0 to 4 after level M command @ echo offdiskcopy A: B: if errorlevel 0 if not errorlevel 1 echo exit 0if errorlevel 1 if not errorlevel 2 Echo exit 1if errorlevel 2 if not errorlevel 3 Echo exit 2if errorlevel 3 if not errorlevel 4 echo exit 3if 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. Note: When you need to test the specific errorlevel value, it is best to use if
% Errorlevel % = value cmmand format. For more information about % errorlevel %, see 《 Difference between errorlevel and % errorlevel %"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.