@echo off
set str=endlocal is success
for %%a in (1) do (
setlocal enabledelayedexpansion
set str=endlocal is failed
call :subroutine
)
cls
echo %str%
pause
exit
::=======================================
:subroutine
endlocal
goto :eof
原帖由 Lumiere 于 2009-9-20 00:52 发表
用call相当于调用子程序,所以你的endlocal放在子程序段,其实结束的只是被调用的子程序的setlocal,不过这里没有而已。可以看做程序从call起转到其他地方执行,其他地方就是endlocal,要注意这是在其他地方执行的, ...
@echo off
set str=endlocal is success
for %%a in (1) do (
goto :b
::===============a==================
:a
endlocal
goto :eof
::===============a==================
:b
setlocal enabledelayedexpansion
set str=endlocal is failed
call :subroutine
)
cls
echo %str%
pause
exit
::=======================================
:subroutine
call :a
endlocal
goto :eof
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |