Sometimes, We need to execute multiple batch files in a dos command line or batch programming.
There are multiple ways to execute .bat files
Let’s have the following batch files
- one.bat
- two.bat
- three.bat
To run all these batch files at once.
you can create a single batch file run.bat file
run.bat contains
one.bat
two.bat
three.bat
on Running run.bat on command, It runs the first file(one.bat) and does not run the remaining batch files(two.bat,three.bat). In this approach, the only first line is executed and stops its execution.
So, DOS has introduced a call command
.
It runs batch file once completed, returns to the calling line like this executes until finished.
Call command to execute multiple files.
Here is the code used to run multiple files. The files execute in sequential order with the order defined in the run.bat file.
call one.bat
call two.bat
call three.bat
on running the run.bat file,
It calls one.bat,two.bat and three.bat files in sequential order.
How to execute multiple files in multiple command prompts.?
It is an example of running multiple files in multiple command prompts. It is opposite to a single command prompt to run multiple files in sequential order.
run.bat
start cmd /k Call one.bat
start cmd /k Call two.bat
start cmd /k Call three.bat
The start
command opens a new command prompt window.
The -k
option tells that must open a new window
Running run.bat do the following things
- It opens three command prompts, each calling batch files
- execution will not wait for the previous window context
- It is the parallel execution of multiple files in multiple commands that prompts context.
- No sequential order, If there is any dependency on each other batch files, and not recommended.
- It would be good to run multiple bat files independently