Waiting for Parallel batch scripts or command lines

前端 未结 2 1676
伪装坚强ぢ
伪装坚强ぢ 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 04:08

    You can call the files easily with this script:

    @echo off
    setlocal
    set "lock=%temp%\wait%random%.lock"
    
    
    call :a one.bat 1
    call :a two.bat 2
    call :wait
    call :a three.bat 1
    call :a name.bat 2
    call :a gfwagwa.bat 3
    
    
    exit /b
    :a
    start "%~2" cmd /c 9>"%lock%%2" %1
    exit /b
    :wait
    1>nul 2>nul ping /n 2 ::1
    for %%N in (%lock%*) do (
      ( rem
      ) 9>"%%N" || goto :Wait
    ) 2>nul
    

    call :wait simply replaces the waiting. Whenever you have called all files that are to be run asynchronously, call the wait function. Then you can call more scripts.

    The second parameter is the number of the lock file. Make sure you don't have duplicate numbers before all those scripts using them are closed (i.e. before the next call :wait). Though you're not going to run out of numbers anyway, no reason to use duplicates.

提交回复
热议问题