I have a .bat file in windows that does three things
cmd1 arg1 arg2
cmd2 arg3
cmd3 arg4 arg5 arg6
Sometimes cmd1 can fail and that's fine, I would like to carry on and execute cmd2 and cmd3. But my bat stops at cmd1. How can I avoid this?
Update for clarity – these are not other .bat files, they are exe commands. Hopefully I don't have to build a tree of .bat files just to achieve this.
Best Answer
Another option is to use the amperstand (
&
)cmd1 & cmd2 & cmd3
If you use a double, it only carries on if the previous command completes successfully (
%ERRORLEVEL%==0
)cmd1 && cmd2 && cmd3
If you use a double pipe (
||
), it only runs the next command if the previous completes with an error code (%ERRORLEVEL% NEQ 0
)cmd1 || cmd2 || cmd3