Waiting for Parallel batch scripts or command lines

前端 未结 2 1674
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 03:28

I am finding it difficult to modify the script here to suit my requirements: https://stackoverflow.com/a/12665498/4683898

@echo off
setlocal
set \"lock=%temp         


        
2条回答
  •  旧巷少年郎
    2020-12-22 03:53

    just to offer an alternative way:

    @ECHO off
    start "MyCommand-%~n0" cmd.exe /c ping localhost
    start "MyCommand-%~n0" cmd.exe /c ipconfig /all
    start "MyCommand-%~n0" cmd.exe /c sysinfo
    :loop
    tasklist /fi "windowtitle eq MyCommand-%~n0"  | find "===" >nul && goto :loop
    echo finished!
    

    Edit for your comment. bunch is the number of commands running in parallel.

    @ECHO off
    setlocal enabledelayedexpansion
    set bunch=3
    
    for /f "delims=:" %%a in ('findstr /n /b "REM ==" %~f0') do set /a datastart=%%a+1
    set count=0
    for /f "skip=%datastart% usebackq delims=" %%a in ("%~f0") do (
      set /a "count=(count+1) %% %bunch%"
      echo starting: %%a
      start "MyCommand-%~n0" cmd.exe /c %%a
      if !count!==0 echo waiting & call :loop
    )
    echo waiting & call :loop
    echo finished!
    goto :eof
    
    :loop
    tasklist /fi "windowtitle eq MyCommand-%~n0"  | find "===" >nul && goto :loop
    goto :eof
    
    REM == START DATA ==
    ping localhost
    ipconfig /all
    systeminfo
    tasklist
    echo hello
    schtasks /query
    wmic bios get /value
    timeout 10
    

    the first for just gets the line number where your commands are (start of DATA section)

提交回复
热议问题