Waiting for parallel batch scripts

前端 未结 4 1716
盖世英雄少女心
盖世英雄少女心 2020-11-28 12:09

I have 4 batch files. I want to run one.bat and two.bat at once, concurrently. After completion of these two batch files, three.bat an

4条回答
  •  无人及你
    2020-11-28 12:49

    Create a master.bat file that starts one.bat and two.bat. When one.bat and two.bat end correctly, they echo to file they have finished

    if errorlevel 0 echo ok>c:\temp\OKONE
    if errorlevel 0 echo ok>c:\temp\OKTWO
    

    Then the master.bat wait for the existence of the two files

    del c:\temp\OKONE
    del c:\temp\OKTWO
    start one.bat
    start two.bat
    :waitloop
    if not exist c:\temp\OKONE (
        sleep 5
        goto waitloop
        )
    if not exist c:\temp\OKTWO (
        sleep 5
        goto waitloop
        )
    start three.bat
    start four.bat
    

    Another way is to try with the /WAIT flag

    start /WAIT one.bat
    start /WAIT two.bat
    

    but you don't have any control on errors.

    Here's some references

    http://malektips.com/xp_dos_0002.html

    http://ss64.com/nt/sleep.html

    http://ss64.com/nt/start.html

提交回复
热议问题