这是一个愚蠢的问题,但请帮帮忙,否则我的大脑会爆炸!;))一些我不明白的愚蠢的事情…
简而言之:为什么在我选择数字7(退出)后,返回的ERRORLEVEL是正确的,但GOTO指定的标签被忽略,而是转到allTasksReboot标签……
这是我的“密码”。
@echo off
mode con: cols=150 lines=65
@echo ------------------------------------------------------------------------------------------------
@echo INSTALLATION MENU
@echo ------------------------------------------------------------------------------------------------
@echo [ 1 ].All tasks - Unattended with reboot on finish
@echo [ 2 ].All tasks - Unattended without reboot on finish
@echo [ 3 ].All tasks except Software group - Unattended with reboot on finish
@echo [ 4 ].All tasks except Software group - Unattended without reboot on finish
@echo [ 5 ].All tasks except Java 7 installation - Unattended without reboot on finish
@echo [ 6 ].Install only VNC - Unattended
@echo [ 7 ].Exit
@echo ------------------------------------------------------------------------------------------------
@echo ------------------------------------------------------------------------------------------------
CHOICE /C:1234567 /N /M "Choose number for installation type."
@echo You press: %ERRORLEVEL%
@pause
IF ERRORLEVEL 1 GOTO allTasksReboot
IF ERRORLEVEL 2 GOTO allTasks
IF ERRORLEVEL 3 GOTO allExceptSoftwareReboot
IF ERRORLEVEL 4 GOTO allExceptSoftware
IF ERRORLEVEL 5 GOTO allTasksExceptJava
IF ERRORLEVEL 6 GOTO onlyVnc
IF ERRORLEVEL 7 GOTO scriptend
:allTasksReboot
@echo **************************************************************************
@echo All tasks - Unattended with reboot on finish
@echo **************************************************************************
@pause
goto scriptend
:scriptend
@echo Lets exit...
@pause
:goexit发布于 2013-06-28 01:21:38
我可能最喜欢使用带有LABEL-<n>名称的单个GOTO,但是@Endoro的解决方案是使用IF ERRORLEVEL的正确方式。如果您不想对If校验进行排序,也可以使用%ERRORLEVEL%的值
IF %ERRORLEVEL% EQU 7 GOTO scriptend
IF %ERRORLEVEL% EQU 5 GOTO allTasksExceptJava
IF %ERRORLEVEL% EQU 2 GOTO allTasks
IF %ERRORLEVEL% EQU 6 GOTO onlyVnc
IF %ERRORLEVEL% EQU 1 GOTO allTasksReboot
IF %ERRORLEVEL% EQU 3 GOTO allExceptSoftwareReboot
IF %ERRORLEVEL% EQU 4 GOTO allExceptSoftwarehttps://stackoverflow.com/questions/17346793
复制相似问题