我有设置变量的情况。根据用户输入选择案例。执行大小写时,变量将被发送到:RUN标签,在那里它们被推送到某些代码中。
我想做什么:当用户输入" ALL"对于输入,有一个循环遍历每个case并通过:RUN标签处理这些变量。我不确定你是否可以设计一个FOR循环来完成所有的情况。我完全乐于接受建议。
由于
SET /P PROCESS="Choose a process to run: "
2>NUL CALL :%PROCESS% # jump to :CASES.
IF ERRORLEVEL 1 CALL :ALL # if label doesn't exist
ECHO Done.
EXIT /B
:PROCESS1
set runProcess1A=Yes
set runProcess1B=No
set runProcess1C=Yes
goto RUN
:PROCESS2
set runProcess2A=Yes
set runProcess2B=Yes
set runProcess2C=Yes
goto RUN
:PROCESS3
set runProcess3A=Yes
set runProcess3B=No
set runProcess3C=No
goto RUN
:ALL
REM CODE NEEDED HERE TO RUN THROUGH ALL THE CASES (PROCESS1 PROCESS2 AND PROCESS3).
:RUN
rem If process1A==Yes, then do something ETC
答案 0 :(得分:0)
这应该做你想要的。
REM Assumes the input will be a number between 1 and 3, or the word ALL
SET /P PROCESS="Choose a process to run: "
SET P1=Yes No Yes
SET P2=Yes Yes Yes
SET P3=Yes No No
IF "%PROCESS%"=="ALL" (
FOR %%Z IN (1 2 3) DO FOR /F "TOKENS=1-3" %%A IN (!P%PROCESS%!) DO (
SET runProcess%Z%A=%%A
SET runProcess%Z%B=%%B
SET runProcess%Z%C=%%C
) ELSE (
FOR /F "TOKENS=1-3" %%A IN (!P%PROCESS%!) DO (
SET runProcess%PROCESS%A=%%A
SET runProcess%PROCESS%B=%%B
SET runProcess%PROCESS%C=%%C
)
)
:RUN
...