Monday, February 21, 2011

Executing multiple commands from a Windows cmd script

I'm trying to write a Windows cmd script to perform several tasks in series. However, it always stops after the first command in the script.

The command it stops after is a maven build (not sure if that's relevant).

How do I make it carry on and run each task in turn please?

Installing any software or configuring the registry etc is completely out of the question - it has to work on a vanilla Windows XP installation I'm afraid.

Ideally I'd like the script to abort if any of the commands failed, but that's a "nice to have", not essential.

Thanks.

From stackoverflow
  • When you call another .bat file, I think you need "call" in front of the call:

    call otherCommand.bat
    
    Darren Greaves : Hi, in the original script I wasn't calling other .cmd files, but I have since split it into separate files so I could run each in turn. So, putting call in front of each command seems to have done the trick, thanks!
  • I don't know the direct answer to your question, but if you do a lot of these scripts, it might be worth learning a more powerful language like perl. Free implementations exist for Windows (e.g. activestate, cygwin). I've found it worth the initial effort for my own tasks.

    Darren Greaves : Thanks but I am unable to install any software. I wish I had access to something more powerful than the crappy Windows scripting language. :-(
    Ferruccio : You can always use vbscript or javascript. They're built into the Windows scripting host.
  • You can use the && symbol between commands to execute the second command only if the first succeeds. More info here http://commandwindows.com/command1.htm

    Darren Greaves : Thanks, I'll give that a try in conjunction with the accepted answer above.
  • Can you post the script?

  • Not sure why the first command is stopping. If you can make it parallel, you can try something like

    start cmd.exe /C 1.bat      
    start cmd.exe /C 2.bat
    
  • Awesome Gulzar really awesome thanx for solving how to run multiple DOS/Windows commands in parallel.

    In case any one needs, I am posting how to do it for Linux/Unix

    Run all three commands in parallel without waiting for the preceding ont to finish :

    command1 ; command2 ; command3

    John Saunders : -1: The question was about Windows.

0 comments:

Post a Comment