How to run multiple batch files from one batch file with a dependency?

I want to run one batch file that runs other batch files. I looked at a similar question that was presented here: How to run multiple .BAT files in a .BAT file

I followed an example (in particular, the very last sentence), and it worked ... partially. He ran the batch files I needed. However, for the applications to function properly, some of these batch files must be opened, and then run their course for several seconds, and then run the next batch file, otherwise they will not be registered. Specifically, the first batch file starts the web application server (JBOSS 5.1), then the next batch file opens the pool manager, and then the other two launch distribution servers. When I run my batch file that calls others, they all start almost simultaneously, and they do not register each other. Can I do this with a batch file? Or do I need to enter the code of other batch files and make changes there? I want to avoid this at all costs.

Here is what I still have:

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 
+6
source share
4 answers

You can discard 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 
+6
source

Answer:

Add the /wait option to the run 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 the ping delay between runs. (See User706837).

Literature:

Technet , Rob , SS64 , DosTips

+4
source

Whenever I have batch files that depend on another, I either: 1. nest them; value, if batch1 needs to be run before batch2, then I add batch2 to package 1. 2. put the "sleep" call in package b2. This is only possible if you are confident enough about the duration of the launch for package 1.

Example sleep command:

ping 127.0.0.1 -n 4 > null

This will make the batch file wait 3 seconds. (Because there is only 3, 1 second, between each of the 4 echoes)

Examples:

 start cmd /k CALL D:\jboss-5.1.0.GA-jdk6\jboss-5.1.0.GA\bin\run.bat ping 127.0.0.1 -n 4 > null start cmd /k CALL batch1.bat ping 127.0.0.1 -n 4 > null start cmd /k CALL batch2.bat ping 127.0.0.1 -n 4 > null start cmd /k CALL batch3.bat 
+1
source
 There are multiple ways for that. 1. rem echo call A CALL a.bat rem echo call B CALL b.bat rem echo call C CALL c.bat rem pause -------------------- 2. echo call A start cmd /k CALL a.bat echo call B start cmd /k CALL b.bat echo call C start cmd /k CALL c.bat pause --------------------- Here the difference is- start cmd /k It creates these many instances. So we can see multiple number of CMD prompts. CALL Each descendent CALL waits for the completion of the previous CALL. 
+1
source

All Articles