我有一个包含不同子程序的脚本:
REM ---------------MAIN------------------------START----------------------------
call :SUB_GetStartTime
call :SUB_SettingVariables
call :SUB_CheckingParameters %*
call :SUB_Copy
call :SUB_GetEndTime
call :SUB_WriteLog
call :SUB_EndScreen
REM ---------------MAIN------------------------END------------------------------
在SUB_CheckingParameters我有这个查询:
if "%~1"=="/help" (
GOTO SUB_HELP
)
如果我传递参数/ help,它会进入我的帮助窗口:
cls
ECHO ===================HELP==============
ECHO help text help text help text
ECHO =====================================
timeout /t 120
exit /b
在exit /b
之后我希望脚本结束,但它只是转到我的下一个子程序(SUB_Copy)。脚本不应该结束,因为我使用GOTO SUB_Help
而不是call
?
有人可以帮助我并告诉我我做错了什么吗?
答案 0 :(得分:1)
我通过传回错误级别来处理这个问题:
@Echo off
REM ---------------MAIN------------------------START----------------------------
call :SUB_GetStartTime
call :SUB_SettingVariables
call :SUB_CheckingParameters %* || Exit /b 1
call :SUB_Copy
call :SUB_GetEndTime
call :SUB_WriteLog
call :SUB_EndScreen
REM ---------------MAIN------------------------END------------------------------
Echo end of main
Pause
Goto :Eof
:SUB_CheckingParameters
if /I "%~1"=="/help" GOTO SUB_HELP
:SUB_GetStartTime
:SUB_SettingVariables
:SUB_Copy
:SUB_GetEndTime
:SUB_WriteLog
:SUB_EndScreen
Echo:We are in %~0 Args %*
Goto :Eof
:SUB_HELP
rem cls
ECHO ===================HELP==============
ECHO help text help text help text
ECHO =====================================
timeout /t 120
exit /b 1