在被调用循环中如何完全停止批处理文件?
exit /b
只是退出 :label 循环,而不是整个批处理文件,而 bareexit
退出批处理文件和父 CMD shell,这是不需要的。
@echo off
call :check_ntauth
REM if check fails, the next lines should not execute
echo. ...About to "rmdir /q/s %temp%\*"
goto :eof
:check_ntauth
if not `whoami` == "nt authority\system" goto :not_sys_account
goto :eof
:not_sys_account
echo. &echo. Error: must be run as "nt authority\system" user. &echo.
exit /b
echo. As desired, this line is never executed.
结果:
d:\temp>whoami
mydomain\matt
d:\temp>break-loop-test.bat
Error: must be run as "nt authority\system" user.
...About to "rmdir /q/s d:\temp\systmp\*" <--- shouldn't be seen!