0

I need to execute two diferent actions in a batch file but I want the second action only run IF the result of the first action run. It’s possible to order the actions in a batch file? My question is because the second action It will be carried by the first action data so it depends on the success of the first action.

How can I do that in a Batch file?

SaCvP
  • 393
  • 2
  • 4
  • 16
  • 1
    See answer on [Single line with multiple commands using Windows batch file](http://stackoverflow.com/a/25344009/3074564). Hopefully the first executed application or command exits with a value greater 0 if not successful. For example the command __del__ always exits with value `0` even if there was no file to delete or deletion of a specified file failed. – Mofi Jan 06 '16 at 19:06

1 Answers1

1

You can use the && operator to join the two commands and only run the second if the first was successful.

echo This always runs && echo This only runs if the previous command was successful.

You can also use || to only run the second command if the first fails.

echo This runs first || echo This is a bad example since echo always runs, but if the first command failed for some reason, this would be displayed.
SomethingDark
  • 13,229
  • 5
  • 50
  • 55