Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I launch multiple batch files from one batch file with dependency?

Tags:

batch-file

I want to run one batch file, that start the other batch files. I looked at a similar question posted here: How to run multiple .BAT files within a .BAT file

I followed the example (specifically the very last suggestion) and it worked...partially. It did launch the batch files that I needed to. However, in order for the applications to function properly, some of these batch files have to open, and then run their course for a few seconds, before the next the next batch file launches, otherwise they won't be registered. Specifically, the first batch file launches a web applications server (JBOSS 5.1), then the next batch file opens a pool manager, then the other two launch distribution servers. When I run my batch file that calls the others, they all launch nearly simultaneously, and they do not register each other. Can I even do this with a batch file? Or do I have to go into the code of the other batch files and make changes there? I want to avoid that at all costs.

Here is what I have so far:

start cmd /k CALL D:\jboss-5.1.0.GA-jdk6\jboss-5.1.0.GA\bin\run.bat

start cmd /k CALL batch1.bat

start cmd /k CALL batch2.bat

start cmd /k CALL batch3.bat
like image 495
David Horvath Avatar asked Dec 21 '12 17:12

David Horvath


2 Answers

You can drop the start cmd /k and just use CALL.

CALL D:\jboss-5.1.0.GA-jdk6\jboss-5.1.0.GA\bin\run.bat
CALL batch1.bat
CALL batch2.bat
CALL batch3.bat
like image 81
aphoria Avatar answered Nov 09 '22 23:11

aphoria


Answer:

Add the /wait option to the start command.

WAIT        Start application and wait for it to terminate.

Example:

start /wait cmd /k CALL D:\jboss-5.1.0.GA-jdk6\jboss-5.1.0.GA\bin\run.bat

start /wait cmd /k CALL batch1.bat

start /wait cmd /k CALL batch2.bat

start /wait cmd /k CALL batch3.bat

Otherwise just use a ping delay between the starts. (See user706837's Answer)

References:

Technet, Rob, SS64, DosTips

like image 44
David Ruhmann Avatar answered Nov 10 '22 00:11

David Ruhmann