Can I run multiple command streams in cmd?

I have about 290 files that I need to optimize in a short amount of time.

When I execute optipng *.png, it takes about 10 minutes to complete the transaction.

However, when I do optipng a*.pngit optipng m*.pngon two separate command lines, it does the job in 5 minutes.

Now I can start about 20 processes at the same time, which will speed up the work and do not take up all the space on my desktop?

+5
source share
2 answers

I wrote a batch file that executed only the maximum number of commands: Parallel execution of shell processes :

@echo off
for /l %%i in (1,1,20) do call :loop %%i
goto :eof

:loop
call :checkinstances
if %INSTANCES% LSS 5 (
    rem just a dummy program that waits instead of doing useful stuff
    rem but suffices for now
    echo Starting processing instance for %1
    start /min wait.exe 5 sec
    goto :eof
)
rem wait a second, can be adjusted with -w (-n 2 because the first ping returns immediately;
rem otherwise just use an address that unused and -n 1)
echo Waiting for instances to close ...
ping -n 2 ::1 >nul 2>&1
rem jump back to see whether we can spawn a new process now
goto loop
goto :eof

:checkinstances
rem this could probably be done better. But INSTANCES should contain the number of running instances afterwards.
for /f "usebackq" %%t in (`tasklist /fo csv /fi "imagename eq wait.exe"^|wc -l`) do set INSTANCES=%%t
goto :eof

, . , , , . , , , - .

, . (%RANDOM%) , ( ), :

@echo off
title %1
"%2" "%3"

, , . , (tasklist /fi "windowtitle eq ..."). . cmd.exe , , .

%NUMBER_OF_PROCESSORS%, .

, psexec ( , , ). .

+2
0

All Articles