How to run multiple .BAT files within a .BAT file

前端 未结 17 1678
别跟我提以往
别跟我提以往 2020-11-22 13:59

I\'m trying to get my commit-build.bat to execute other .BAT files as part of our build process.

Content of commit-build.bat:



        
相关标签:
17条回答
  • 2020-11-22 14:19

    Just use the call command! Here is an example:

    call msbuild.bat
    call unit-tests.bat
    call deploy.bat
    
    0 讨论(0)
  • 2020-11-22 14:21

    Try:

    call msbuild.bat
    call unit-tests.bat
    call deploy.bat
    
    0 讨论(0)
  • 2020-11-22 14:22

    You are calling multiple batches in an effort to compile a program. I take for granted that if an error occurs:
    1) The program within the batch will exit with an errorlevel;
    2) You want to know about it.

    for %%b in ("msbuild.bat" "unit-tests.bat" "deploy.bat") do call %%b|| exit /b 1
    

    '||' tests for an errorlevel higher than 0. This way all batches are called in order but will stop at any error, leaving the screen as it is for you to see any error message.

    0 讨论(0)
  • 2020-11-22 14:23

    To call a .bat file within a .bat file, use

    call foo.bat
    

    (Yes, this is silly, it would make more sense if you could call it with foo.bat, like you could from the command prompt, but the correct way is to use call.)

    0 讨论(0)
  • 2020-11-22 14:23

    Run Multiple Batch Files Parallelly

    start "systemLogCollector" /min cmd /k call systemLogCollector.bat
    start "uiLogCollector" /min cmd /k call uiLogCollector.bat
    start "appLogCollector" /min cmd /k call appLogCollector.bat
    

    Here three batch files are run on separate command windows in minimized state. If you don't want them minimized, then remove /min. Also, if you don't need to control them later, then you can get rid of the titles. So, a bare-bone command will be- start cmd /k call systemLogCollector.bat


    If you want to terminate them-

    taskkill /FI "WindowTitle eq appLogCollector*" /T /F
    taskkill /FI "WindowTitle eq uiLogCollector*" /T /F
    taskkill /FI "WindowTitle eq systemLogCollector*" /T /F
    
    0 讨论(0)
  • 2020-11-22 14:24

    If we have two batch scripts, aaa.bat and bbb.bat, and call like below

    call aaa.bat
    call bbb.bat
    

    When executing the script, it will call aaa.bat first, wait for the thread of aaa.bat terminate, and call bbb.bat.

    But if you don't want to wait for aaa.bat to terminate to call bbb.bat, try to use the START command:

    START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/AFFINITY <hex affinity>] [/WAIT] [/B] [command/program]
      [parameters]
    

    Exam:

    start /b aaa.bat
    start /b bbb.bat
    
    0 讨论(0)
提交回复
热议问题