Description: | Command1 && SuccessCommand
Command1 || FailCommand Command1 && SuccessCommand || FailCommand The && operator can be used to execute a command only when the previews command succeeded. The || operator can be used to execute a command only when the previews command failed. Example 1 Show a message only when the string "ERROR" exist in the logfile.log file. The find command succeeds when the string "ERROR" exist in logfile.log. The output of the find command is redirected into the NUL devise since we don`t want to see any of its output in the output window. Example 2 Show a message only when the string "ERROR" doesn`t exist in the logfile.log file. The find command fails when the string "ERROR" doesn`t exist in logfile.log. The output of the find command is redirected into the NUL devise since we don`t want to see any of its output in the output window. Example 3 The Conditional Execution operators are useful with many DOS commands, i.e. the SET command. Note Be careful when combining the operators, i.e.: Command1 && (CommandBlock2) || (CommandBlock3)
To avoid this pitfall force CommandBlock2 to succeed, i.e. using a simple REM as last block command: Command1 && (CommandBlock2 & REM) || (CommandBlock3) or: Command1 && ( CommandBlock2 REM force success ) || ( CommandBlock3 ) |
||
Script: | Download: BatchConditionalExecution.bat
|
||
Script Output: |
|