如果行失败则中断批处理文件

时间:2018-03-01 22:06:27

标签: batch-file batch-processing

这是批处理代码;

echo off
echo ZD Install is currently loading the setup
echo Please wait...
start "" /w "\\products\setup.exe"
start "" /w "\\SP1\update.exe"
start "" /w "\\SP2\update.exe"

我如何制作它以便如果setup.exe关闭或失败,它将不会运行SP1和SP2,并发出一条消息说它失败了?

1 个答案:

答案 0 :(得分:0)

未经测试,但这样的事情应该有效:

@setlocal ENABLEEXTENSIONS
@rem @set prompt=$G

@echo ZD Install is currently loading the setup
@echo Please wait...
@call "\\products\setup.exe"
@if %ERRORLEVERL% @goto :ProductsSetupFailed
@call "\\SP1\update.exe"
@if %ERRORLEVERL% @goto :SP1UpdateFailed
@call "\\SP2\update.exe"
@if %ERRORLEVERL% @goto :SP2Failed
@exit /b 0

:ProductsSetupFailed
@call :ShowError "Product setup" %ERRORLEVEL%
@exit /b %ERRORLEVEL%

:SP1UpdateFailed
@call :ShowError "SP1 setup" %ERRORLEVEL%
@exit /b %ERRORLEVEL%

:SP2UpdateFailed
@call :ShowError "SP2 setup" %ERRORLEVEL%
@exit /b %ERRORLEVEL%

:ShowError
@echo %~1 failed: %2
@exit /b %2