I am trying to modify some excellent code for multithreading batch commands, by dbenham : Parallel execution of shell processes (should not be required to read to solve my problem).
It currently takes the commands from reading a file reference. I want to instead send the commands in via arguments. This will basically only need a single for loop to be modified.
The problem is no matter what variations I try I can not get the correct split out of the for-loop. I am obviously missing something basic with delimiters or something despite reading the documentation multiple times. This is likely pretty trivial for a more experienced batch scripter I expect, but I am thoroughly stuck...
I am certain that the only thing that needs to change is a single for-statement:
(snippet of multithread.bat)
for /f "tokens=* delims=:" %%A in ('findstr /b ":::" "%~f0"') do (
This currently does : "Search in the calling script file (from %~f0) for any lines starting with ::: and make each of those %%A in the for-loop". This works great, but...
I want to modify this to instead take the lines (commands) from arguments, preferably by just parsing from %* (all arguments). The input format and order of arguments are arbitrary so feel free to change it as you want if it makes more sense another way.
Let me illustrate with a basic example how it might look in practice:
(main script - for illustration)
::these are the commands we want to run, ideally I'd like to support an arbitrary number of them
set command1="rclone size remote1:"
set command2="rclone size remote2:"
set command3="rclone size remote3:"
call multithread.bat /O 2 %command1% %command2% %command3%
:: /O indicates we ask for more verbose output from the command controller
:: 2 indicates the desired max amount of conurrently running threads
:: We just want to skip these in the for-loop as they are picked up elsewhere in the script.
So what should that for-loop look like to make %%A be command 1,2,3 (and ect. if more commands) ? For example, in the first run of the loop, %%A should in this example be:
rclone size remote1:
then...
rclone size remote2:
the second time ect.