for and start commands in a batch for parallel and sequential work

后端 未结 2 1087
南旧
南旧 2021-01-15 18:37

I have an 8 core CPU with 8GB of RAM, and I\'m creating a batch file to automate 7-zip CLI in exhausting most parameters and variables to compress the same set of files with

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-15 19:30

    To execute at the same time no more than 8 instances of 7z.exe process you could do this:

    @Echo OFF & Setlocal EnableDelayedExpansion
    
    Set /A "pCount=0" & REm Process count
    
    For
    ...
    ) DO (
         Set /A "pCount+=1"
         If !pCount! LEQ 8 (
           Start /B 7z.exe a teste.resultado\%%xx.ppmd.%%dd.%%ww.%%ss.7z .\teste.original\* -mx=%%x -m0=PPMd:mem=%%d:o=%%w -ms=%%s
         )
    )
    ...
    

    If do you want to run each process in a new parallel CMD window then you would replace the Start /B line on my code for this else:

    CMD /C "Start /w 7z.exe a teste.resultado\%%xx.ppmd.%%dd.%%ww.%%ss.7z .\teste.original\* -mx=%%x -m0=PPMd:mem=%%d:o=%%w -ms=%%s"
    

提交回复
热议问题