0

I have a Windows batch script which basically loops through a directory and searches for subdirectories, and then it calls an executable program (.exe), and gives the found subdirectory as an argument to the executable program.

for a SubDir in the Directory:
   call Program.exe -argument "SubDir" ...

As per current implementation the calling of Program.exe is sequential, i.e. each subdirectory is processed one after another. This is rather slow since I have >20 subdirectories. Therefore, I would like to improve the runtime of the processing. One way how the the whole batch script would run much faster would be if I could run the Program.exe in parallel on multiple cores/threads. Could this be possible in a batch script or would I have to write a little python/java program to do the parallel processing? Of course, my batch script would have to then call this python/java program.

Mofi
  • 42,677
  • 15
  • 72
  • 128
  • I guess [this](https://stackoverflow.com/questions/5534324/how-to-run-multiple-programs-using-batch-file) answered question is very similar to yours. Give it a try. – SYNEC May 20 '22 at 13:19
  • Thanks. I found a similar post that also recommends using the 'start' command to make an executable scheduled in parallel (on different cores presumably). From my understanding on each call of the 'start' command, a new process is created and a batch script continues its execution without any blocking. However, will the batch script upon its termination wait for the all started processes to terminate first, before it terminates itself? I would have to make sure that once the batch process finishes its execution that also other processes have finished as well. How to synchronize this? – SimpleThings Jun 01 '22 at 13:24
  • With the parameter '/wait' the script starts the app and only closes after the app is closed. But while it waits it doesn't start any other apps, so the script pauses there and would only start the next one after the previous is finished... – SYNEC Jun 02 '22 at 06:07
  • Ok, but that would then mean that the execution of each app is then basically sequential, and not parallelized. My idea was to run all apps in parallel, and let the batch script end after the apps have terminated. I guess that would require some type of a lock/semaphore which would allow script terminating only once all started processes/apps have terminated. – SimpleThings Jun 03 '22 at 13:21

0 Answers0