Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
You should be able to start the command using cmd /C. –  Oliver Salzburg Jan 3 '13 at 22:49
1  
You need to show a specific code example of what is not working. Batch files normally do not terminate automatically if a command fails with an error. Batch files do terminate if there is a syntax error. If your code is exiting upon an exe error, then there must be logic in your code that is causing that behavior. –  dbenham Jan 4 '13 at 14:59

2 Answers 2

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

share|improve this answer
    
Can I do this when passing args also? I just tried and it didn't see to work. –  ConfusedNoob Jan 3 '13 at 22:39
    
@ConfusedNoob I do all the time... I have a CHKDSK command, with arguments, that works. I type check D: & check E: & check F:, and it works. The arguments the BAT file has include the /perf /f /r /b /scan switches –  Canadian Luke Jan 3 '13 at 23:14
    
good one! brought me an idea how to implement several retries: cmd || cmd || ... will execute next cmd until succeeds –  iTake Nov 11 '13 at 17:21
    
This makes long scripts unreadable, is there no other way? –  jan Oct 10 at 7:53
    
@Jan how does it make long scripts unreadable? –  Canadian Luke Oct 10 at 14:09

Presumming the cmds are other .bat files stack the commands like this:

 call cmd1
 call cmd2
 call cmd3
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.