In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to use the compound statement connectors of batch commands". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn how to use the compound statement connectors of batch commands.
Help Information:
The code is as follows:
& [...] Command1 & command2 is used to separate multiple commands on a command line. Cmd.exe runs the first command, then the second command.
& & [.] Command1 & & command2 is used to run commands following the symbol only if the command preceding the symbol & & is successful. Cmd.exe runs the first command, and then the second command only if the first command is successful.
| | [...] Command1 | | command2 is used to run the symbol | | the following command only if the previous command fails. Cmd.exe runs the first command, and then the second command only if the first command fails (an error code greater than zero is received).
The above is the official help information (quoted in ntcmds.chm), it is best to use googl search to download one.
Command summary:
& generally pronounce "and".
Detailed description of parameters:
1. Let's talk about it first.
The official explanation of "used to separate multiple commands on a command line" is actually from the perspective of the interpreter. From a human point of view, it should be "connecting multiple commands".
For example, I want to output hello and world 2 lines of text and connect the two echo commands with "&".
The code is as follows:
@ echo off
Echo hello & echo world
Pause
The most common problem with the use of "&" is variable latency, for which you can refer to the section on this knowledge point in batch for statements from getting started to mastering.
two。 Let's talk about ErrorLevel.
ErrorLevel consists of two words, one Error and one Level. If you combine these two words, the literal meaning is "number of errors" or "type of error".
If the command is executed successfully, then the "number of errors" is naturally zero. If the execution fails, then the number of errors is non-zero.
Posts about ErrorLevel:
The influence of batch Internal Command on error return Code errorlevel
Some guesses about errorlevel in batch processing
3. If the command before the symbol is executed successfully, the command after the symbol is executed.
Output hello and world 2 lines of text, and connect the two echo commands with "& &".
The code is as follows:
@ echo off
Echo hello & & echo world
Pause
The result of execution is exactly the same as when you link two commands with "&", so is the function the same as "&" and "&"?
The answer is: their functions are completely different, and the same result is just a coincidence.
The function of "&" is merely to link multiple commands, while the purpose of "&" is to determine whether the command in front of the symbol is executed successfully, and thus whether to execute the command after the symbol.
Here is an example to illustrate:
The code is as follows:
C:\ Users\ helloworld\ Desktop > start "" 111.txt "& & echo hello
The system cannot find the file 111.txt.
C:\ Users\ helloworld\ Desktop > start "" 111.txt "& echo hello
The system cannot find the file 111.txt.
Hello
Use the start command to open a file that does not exist. Since the file does not exist, the execution of the start command fails. The command "echo hello" linked with "&" is not executed, but is executed with the "&" link.
This characteristic of "&" makes it a special conditional operator.
4. Execute the command after the symbol if you fail to execute the command before the symbol
The negative action of & & is |.
For example:
The code is as follows:
C:\ Users\ helloworld\ Desktop > start "" 111.txt "| | echo hello
The system cannot find the file 111.txt.
Hello
Thank you for reading, the above is the content of "how to use compound statement connectors of batch commands". After the study of this article, I believe you have a deeper understanding of the problem of how to use compound statement connectors of batch commands, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.