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 follo
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.
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
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
Whenever I have batch files that depend on another I either: 1. nest them; meaning, if batch1 needs to run before batch2, then I add batch2 within batch1. 2. put a 'sleep' call within batch2. This is only possible if you are fairly certain of the startup duration for batch1.
A sample sleep command is:
ping 127.0.0.1 -n 4 > null
This will make the batch file wait for 3 seconds. (Because there are only 3, 1 second sleeps, between each of the 4 echos)
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