【问题标题】:Exit and re-enter loop in Windows batch file在 Windows 批处理文件中退出并重新进入循环
【发布时间】:2017-08-08 21:20:44
【问题描述】:

我需要循环浏览批处理文件中的列表,设置变量,退出循环然后重新进入。

if "%scale%" == "ind" (

    FOR %%A IN %inclpeople% do (
        set person=%%A
        goto :start
        :cyclepeople
        echo  Done %person%
    )
    goto :end
)

set person=%scale%


:start
echo  Starting with %person%
call  %batch%\findperson
      if %errorlevel% neq 0 goto :failed


call  %batch%\dosomethingelse
      if %errorlevel% neq 0 goto :failed


:finish
if "%scale%" == "ind" (
    goto :cyclepeople
)

:end
call %footer%\success
exit /b 0

所以,如果 scale 不是“ind”(在这种情况下它可能是“all”,则只启动并运行一次命令。如果 scale 等于“ind”,则循环遍历人员列表,设置人员循环变量,开始并返回循环,直到列表完成,然后转到结束。

目前,这仅适用于第一个循环并回显“Done Adam”(例如第一人称),但随后会结束。

【问题讨论】:

  • 抱歉,gotos 和forif 语句中可能没有标签。使用call :label(看起来你试图模仿它)
  • 谢谢!!这非常有效!

标签: loops batch-file


【解决方案1】:

为了将来参考,我将根据上面斯蒂芬的评论回答问题:

if "%scale%" == "ind" (

    FOR %%A IN %inclpeople% do (
        set person=%%A
        call :start
        echo  Done %person%
    )
    goto :end
)

set person=%scale%


:start
echo  Starting with %person%
call  %batch%\findperson
      if %errorlevel% neq 0 goto :failed


call  %batch%\dosomethingelse
      if %errorlevel% neq 0 goto :failed


:finish
if "%scale%" == "all" (goto :end)
goto :eof

:end
call %footer%\success
exit /b 0

【讨论】:

    猜你喜欢
    • 2011-10-07
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多