In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use IF-ERRORLEVEL". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The code is as follows:
@ echo off
: p
Ping 61.152.XX.XX
IF ERRORLEVEL 1 goto aa
IF ERRORLEVEL 0 goto bb
: aa
Echo is restarting the software service.
Net stop MSSQLSERVER
Net start MSSQLSERVER
Goto p
: bb
Echo continues to be in ping.
Goto p
The purpose of this command is to ping 61.152.XX.XX the IP, restart the mssql service if the ping is not available, and then continue to ping, if you can ping, or continue to ping...
We all know that if is a conditional judgment statement under the command line, and ERRORLEVEL is one of its parameters, which translates to the meaning of "error return code". Its function is to judge the error return value of the previous command, then compare it with the defined character value, and then decide what action to take.
The format is as follows:
If ERRORLEVEL nubmer commend
Example: the return value of if ERRORLEVEL 1 echo is equal to 1
So you're going to ask, how do I get the return value of the previous command?
The method is simple. Take ping. Let's run a ping 127.0.0.1 first.
The running result is Reply from 127.0.0.1: bytes=32 timeTEST4
If the file copy is successful, the screen displays "copy file successfully", otherwise "file copy failed" is displayed.
IF ERRORLEVEL is used to test the return value of its last DOS command, note that it is only the return value of the previous command, and the return value must be judged in order from highest to lowest.
So the following batch file is incorrect:
@ ECHO OFF
XCOPY C:\ AUTOEXEC.BAT D:\
IF ERRORLEVEL 0 ECHO successfully copied the file
IF ERRORLEVEL 1 ECHO could not find the copy file
IF ERRORLEVEL 2 ECHO user aborts copy operation through ctrl-c
IF ERRORLEVEL 3 ECHO preset error prevents file copy operation
IF ERRORLEVEL 4 disk write error during ECHO copy
Regardless of whether the copy is successful or not, the following:
Copy file not found
The user aborts the copy operation through ctrl-c
Preset error prevents file copy operation
Write disk error during copy
Will be displayed.
Here are the return values of several commonly used commands and what they represent:
Backup
0 backup successful
1 backup file not found
2 File sharing conflicts prevent backups from being completed
3. Users abort backup with ctrl-c
4 the backup operation was aborted due to a fatal error
Diskcomp
0 disk is the same.
One set is different.
2 the user aborts the comparison operation through ctrl-c
3 the comparison operation is aborted due to a fatal error
4 comparison of preset error abort
Diskcopy
0 disk copy operation succeeded
1 non-fatal disk read / write error
2 the user ends the copy operation through ctrl-c
3 abort the copy of the disk due to a fatal processing error
4 preset error prevents copy operation
Format
0 formatted successfully
3 the user aborts the formatting process through ctrl-c
4 the format was aborted due to a fatal processing error
5 prompting "proceed with format (yzone)?" The next user types n to end.
Xcopy
0 successfully copied the file
1 copy file not found
2 the user aborts the copy operation through ctrl-c
4 preset error prevents file copy operation
5 disk writing error during copy
This is the end of "how to use IF-ERRORLEVEL". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.