Run multiple batch files simultaneously in background every 2 seconds

I have been working on developing a custom monitoring tool to monitor Version Store information for Row versioning and snapshot isolation performance on tempdb.

Have to run a multiple SQL scripts I developed simultaneously and in background every 2 sec. So had three requirements to it basically

  • Run multiple batch files simultaneously
  • Run all the batches every 2 sec
  • Run them all in background so you don’t see the cmd prompt every time the scripts are called.

Run batch files Simultaneously:

Create a master batch file (Monitor.bat) to call the multiple batch scripts simultaneously from master batch file. Use start cmd.exe for each of the batch to run.

start cmd.exe /C  D:\batch1.bat
start cmd.exe /C  D:\batch2.bat
start cmd.exe /C D:\batch3.bat

Run all the batches every 1 sec

To run all the three batches every 1 sec, create a loop with a 1 sec delay; Now the only way to stop this loop would be to close the monitor.bat cmd prompt.

:Loop

start cmd.exe /C  D:\batch1.bat
start cmd.exe /C  D:\batch2.bat
start cmd.exe /C D:\batch3.bat

timeout /T 2
GOTO :Loop

Run them all in background so you don’t see the cmd prompt every time the scripts are called.

Use the /min option to run the cmd in minimized / background mode

The complete Monitor.bat master batch will look like below:

:Loop

start /min cmd.exe /C  D:\batch1.bat
start /min cmd.exe /C  D:\batch2.bat
start /min cmd.exe /C D:\batch3.bat

timeout /T 2
GOTO :Loop

This entry was posted in .bat scripts, Tricks, Windows and tagged . Bookmark the permalink.

Leave a Reply