批量转到条件

Nep*_*l12 0 cmd batch-file

我想调用参数为true的特定子例程.如果两个参数均为false,则退出.我尝试了不同的东西,但我无法找到解决问题的方法.

我有以下场景:

echo OFF
set APP=TRUE
set BPP=TRUE

IF /i "%APP%"=="true" goto sub1
IF /i "%APP%"=="true" goto sub2

echo Both are set false
goto CLOSE

:sub1
echo This is sub1

:sub2
echo This is sub2

:CLOSE
echo Nothing is selected 
exit /B 1
Run Code Online (Sandbox Code Playgroud)

场景如下:如果ONLY APP为真,我只想执行sub1,如果只有BPP为真,那么我只想要执行sub2.如果APP和BPP都为真,则必须首先执行sub1,并且必须执行sub2.但是,如果APP和BPP都设置为false,则必须执行CLOSE.

提前致谢.

Ste*_*han 5

使用call(返回)代替goto.你忘了结束你的子程序,所以代码将"贯穿":

echo OFF
set APP=TRUE
set BPP=TRUE

if /i "%APP%%BPP%"=="falsefalse" (
  echo Both are set false
  echo Nothing is selected 
  exit /B 1
)   
IF /i "%APP%"=="true" call :sub1
IF /i "%BPP%"=="true" call :sub2
echo done.
exit /b 0

:sub1
echo This is sub1
goto :eof

:sub2
echo This is sub2
goto :eof
Run Code Online (Sandbox Code Playgroud)