0

I have this batch command

@echo off
FOR %%i in (C:\input\*.*) DO (
echo processing %%i
if not exist "C:\output\%%i" process.exe "%%i" -out "C:\output\%%i"
)
echo ---- finished ----
pause

Here my tool process.exe processes in a loop all files within a directory - if a result doesn't already exist.

Now my CPU is fast enough to run this process.exe on 2 or 3 files at the same time which would make the processing of the files much faster.

Question: How do I have to change the command to make my batch file processing 2-3 files at the same time?

Impostor
  • 2,080
  • 22
  • 43

1 Answers1

2

The following starts processes up to a max count of %bunch%. Whenever one of them finishes, another one will be started.

@ECHO off
setlocal enabledelayedexpansion
set bunch=3

for %%a in (C:\input\*) do (
  call :loop 
  echo processing: %%a
  start "MyCommand" cmd /c timeout 60
  REM if not exist "C:\output\%%i" start "MyCommand" cmd /c process.exe "%%i" -out "C:\output\%%i"

)
call :loop
goto :eof

:loop  REM waits for available slot
echo on
for /f %%x in ('tasklist /fi "windowtitle eq MyCommand"  ^| find /c "cmd.exe"') do set x=%%x
if %x% geq %bunch% goto :loop
echo off
goto :eof

I don't have your process.exe, so I have to guess. but the REMed line should work for you. (the timeout command is just to show the princip)

Stephan
  • 53,940
  • 10
  • 58
  • 91