multithreadingbatch-filewgetsimultaneous-calls

batch script: loop and labels


I am trying to make a script (batch in windows) that download 5 text files using wget, and do some operations to each one, so I am thinking to do this with a loop just like this

set i=0
:begin
set /a i=%i%+1
if %i% equ 5 exit
wget ".....file1.txt"
goto operations

:operations
stuff
stuff
goto begin

well, it should work, but this will take a lot of time, I want the batch to do it in an efficient way, because in this way it will download one (take some time) and will do the opeartions. What I want to do is to make it a multi threaded, I mean to make it do these 5 files (download+operations) simultaneously.

thanks


Solution

  • If you made the actual process of wget + processing a separate batch file, you can then "start" the batch file which will spawn it as a sub process and continue on in your main batch file eg.

    batchfile1.cmd
    <do something really long>
    
    batchfile2.cmd
    
    for %%N in (a b c d e f g) do start batchfile1.cmd %%n
    

    you'll end up with a-g running all at the same time - however you cant easily then tell when all have finished.