Using conditional processing symbols, you can create multiple commands with just one command line or script. When you use the conditional processing symbol to execute multiple commands, the instructions to the right of the conditional processing symbol act on the results of the command to the left of the conditional processing symbol.
For example, you can run a command only if the previous command failed. Alternatively, perform the command only if the previous command was successful.
Running some commands with the character “&”
command1 & command2 echo foo & echo bar
Running some commands with the character “&&”
command1 &&command2 echo foo && amp echo bar
Run some commands with the character “|| “
command1 II command2 echo foo || echo bar
If using the “||” character, CMD will run the first command (command1). The second command (command2) will only be executed if the first command did not complete successfully (received an error code greater than zero).
Ampersands (&), pipes (|), and parentheses () are special characters that must be preceded by an escape character (^) or quotation marks when you pass them as arguments.
Adding the escape character “^” before the command symbol allows it to be treated as plain text. Characters that usually have this special meaning can be passed and treated like ordinary characters: & \ ^ |
Echo THIS ^& THAT Echo Heading1 ^| heading2 ^| heading3
If a command successfully completes the operation, it returns zero exit code (0) or no exit code. For more information about exit codes.