遇到错误时停止执行批处理脚本

Ton*_*ony 6 dos batch-file batch-processing

所以我使用相同的批处理脚本构建多个客户端.如果在构建一个错误时出现错误,则该过程将停止并继续下一个过程.因为屏幕上有很多输出而我正在做其他事情,大部分时间我都想念有一个构建错误.

如果出现错误,有没有办法停止执行以下任务,并显示弹出消息以引起我的注意?或者至少停止执行所以当我回到命令窗口时,我可以看到出现故障?

@echo off

if "%1"=="?" GOTO HELP

if NOT "%1"=="" set rev=%1
if NOT "%2"=="" set version=%2

@echo on
rem build one 
call perl buildClient.pl -brandName="myBrand" -group="group1" 

rem build two 
call perl buildClient.pl -brandName="myBrand" -group="group2" 

rem build three
call perl buildClient.pl -brandName="myBrand" -group="group3" 

rem build four 
call perl buildClient.pl -brandName="myBrand" -group="group4" 


    @echo off

    goto EXIT

    :HELP
    cls
    echo.
    echo.
    echo usage: buildbrand.bat [revision] [version] [group]
    echo.
    echo        ?           = this help screen
    echo.
    echo        revision    = build version
    echo                      Example: 5.2.31
    echo        group       = group of phones or phone name
    echo                      Example: SonyEricsson\K750
    echo.
    :EXIT
    set version=
    set rev=
    set brandName=
    PAUSE
Run Code Online (Sandbox Code Playgroud)

小智 6

“在if语句中检查错误级别,然后退出/ b(仅退出批处理文件,而不退出整个cmd.exe进程),将其值设置为1或更大。”

if %errorlevel% neq 0 exit /b %errorlevel%
Run Code Online (Sandbox Code Playgroud)

在此处查看详细信息:遇到错误如何使批处理文件终止?