In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to perform conditional processing in batch bat programs. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The following code is generated using if /? > C:\ help.txt.
-
Performs conditional processing in a batch program.
IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command
NOT specifies that Windows XP is only available if the condition is false
The command should be executed.
ERRORLEVEL number if the last running program returns an equal to or greater than
Specifies the exit code of the number and the condition is true.
String1==string2 if the specified text string matches, the specified condition is true.
EXIST filename if the specified file name exists, the specified condition is true.
Command specifies the command to execute if the condition is met. If the specified
The condition is FALSE, and the command can be followed by an executive ELSE.
ELSE command of the command after the keyword.
The ELSE clause must appear on the same line after IF. For example:
IF EXIST filename. (
Del filename.
) ELSE (
Echo filename. Missing.
)
Because the del command needs to be terminated with a new line, the following clause will not be valid:
IF EXIST filename. Del filename. ELSE echo filename. Missing
Because the ELSE command must be on the same line as the end of the IF command, the following clause
It will not be valid:
IF EXIST filename. Del filename.
ELSE echo filename. Missing
If they are all on the same line, the following clause is valid:
IF EXIST filename. (del filename.) ELSE echo filename. Missing
If the command extension is enabled, the IF changes as follows:
IF [/ I] string1 compare-op string2 command
IF CMDEXTVERSION number command
IF DEFINED variable command
Where the comparison operator can be:
EQU-equals
NEQ-not equal to
LSS-less than
LEQ-less than or equal to
GTR-greater than
GEQ-greater than or equal to
And / I switch; if this switch is specified, the string comparison to be made is not divided
Case. The / I switch can be used in the form of IF's string1==string2. These.
Comparisons are universal; the reason is that if both string1 and string2 are composed of numbers
The string is converted to a number and the number is compared.
The effect of the CMDEXTVERSION condition is the same as that of ERRORLEVEL, except for it
Is compared to the build number associated with the command extension. The first version
It's 1. Each time there is a considerable enhancement to the command extension, the version number is increased by one.
The CMDEXTVERSION condition is not true when the command extension is disabled.
If an environment variable is defined, the DEFINED condition works the same as EXISTS
Except that it gets an environment variable, the result returned is true.
If there is no environment variable named ERRORLEVEL,% ERRORLEVEL%
Will be expanded to a string expression of the current value of ERROLEVEL; otherwise, you will get
Its value. After running the program, the following statement describes the use of ERRORLEVEL:
Goto answer%ERRORLEVEL%
: answer0
Echo Program had return code 0
: answer1
Echo Program had return code 1
You can also use the above numbers to compare:
IF ERRORLEVEL% LEQ 1 goto okay
If there is no environment variable named CMDCMDLINE,% CMDCMDLINE%
Expand to the original passed to the CMD.EXE before any processing by the CMD.EXE
The command line; otherwise, you will get its value.
If there is no environment variable named CMDEXTVERSION
% CMDEXTVERSION% will be expanded to the current value of CMDEXTVERSION
A string expression; otherwise, you get its numeric value.
Thank you for reading! On "how to implement batch bat program conditional processing" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
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.