DOS批处理菜单在按Enter键时进入错误级别1



我已经为我的BBS和Echomail Hub制作了一个DOS Batch菜单。原始版本不包含任何错误级别行,当用户按回车键时,批处理将崩溃以提示 .我将错误级别行添加到每个GOTO组,现在当用户按回车键时,它会进入错误屏幕,再次按回车键将用户带回主菜单,而不是崩溃提示。当用户按 Enter 时,必须有一种更简洁的方式来"循环"回到主菜单,除了显示错误屏幕之外没有其他命令。我在这里进行了研究,发现了其他批处理菜单的"报价"修复程序,但这根本不起作用,并且使巴赫不起作用。这是我的批次的副本.主要关注点:如何在没有其他命令的情况下按回车键时将巴赫循环到菜单。谢谢

ECHO OFF
:menu
CLS
Type c:MYSTICDOSMENU.ANS
SET /P M=Choose 1-22 =(
IF %M%==1 GOTO exit 
IF %M%==2 GOTO nodelists
IF %M%==3 GOTO purge
IF %M%==4 GOTO mailin
IF %M%==5 GOTO back
IF %M%==6 GOTO Netrunner
IF %M%==7 GOTO kill
IF %M%==8 GOTO TOP
IF %M%==9 GOTO fidopoll
IF %M%==10 GOTO BOX
IF %M%==11 GOTO fig
IF %M%==12 GOTO CMD
IF %M%==13 GOTO MIS404
IF %M%==14 GOTO MIS2404
IF %M%==15 GOTO MIS606
IF %M%==16 GOTO MIS2606
IF %M%==17 GOTO MRC
IF %M%==18 GOTO DOORPARTY     
IF %M%==19 GOTO FORCEHUB
IF %M%==20 GOTO MISHUB
IF %M%==21 GOTO MIS2HUB
IF %M%==22 GOTO HUBCONFIG
IF %M%==  GOTO MENU
:exit
ECHO OFF
exit
IF ERRORLEVEL 1 GOTO Error
;Start of BBS Commands
;Import All Node Listings
:nodelists
c:
cdmystic
start mutil nodelists
IF ERRORLEVEL 1 GOTO Error
goto menu
;Purge all Old EchoMail
:purge
c:
cdmystic
start mutil purge
IF ERRORLEVEL 1 GOTO Error
GOTO Menu 
;Process mailin Mutil 
:mailin
c:
cdmystic
start mutil mailin
IF ERRORLEVEL 1 GOTO Error
GOTO Menu 
;Backup BBS and Hub
:back
c:
cdmystic
start mysticbu
IF ERRORLEVEL 1 GOTO Error
goto menu
;Load Netrunner
:netrunner
c:
cdnr20b18w
start netrunner.exe
IF ERRORLEVEL 1 GOTO Error
goto menu 
;Kill all Busy nodes
:kill
cd
c:
cdmystic
start fidopoll killbusy
IF ERRORLEVEL 1 GOTO Error
GOTO Menu
;Gernerate Top Callers Report
:TOP
c:
CDMystic
START fidopoll killbusy
IF ERRORLEVEL 1 GOTO Error
GOTO Menu
;Forced Fidopoll of all Nodes on the BBS
:Fidopoll
c:
cdmystic
start fidopoll forced
IF ERRORLEVEL 1 GOTO Error
goto menu

;Load DOSBox
:BOX
c:
CdPROGRAM FILES (x86)DOSBOX-0.74
start DOSBOX
IF ERRORLEVEL 1 GOTO Error
GOTO MENU 
;Start BBS Config Program
:fig
c:
cdmystic
START mystic -cfg
IF ERRORLEVEL 1 GOTO Error
GOTO MENU
;Goto CMD/Prompt
:CMD
c:
CD
START CMD
IF ERRORLEVEL 1 GOTO Error
GOTO MENU
;Start standard mystic internet server for the BBS 
:MIS404
c:
CDMYSTIC
start mystickeep.bat
IF ERRORLEVEL 1 GOTO Error
GOTO MENU 
;Start Mystic internet server II BBS
:MIS2404
c:  
CDMYSTIC
start MIS2 SERVER
IF ERRORLEVEL 1 GOTO Error
GOTO MENU 
;Start Standard MIS for the file server
:MIS606
c:
CDmysticfs
START MIS
IF ERRORLEVEL 1 GOTO Error
GOTO MENU
;Start MIS II for the file Server
:MIS2606
c: 
CDMysticFS
START MIS2 SERVER
IF ERRORLEVEL 1 GOTO Error
GOTO Menu
;Load Mystic Relay Chat
:MRC 
c:
CDMYSTIC
START MRC2
IF ERRORLEVEL 1 GOTO Error
GOTO MENU
;Load DoorParty Service
:DOORPARTY
C:
CD"Program Files (x86)DoorParty Connector"
START doorparty-connector.exe
IF ERRORLEVEL 1 GOTO Error
GOTO MENU
;Start of Hub Commands
;Load FSXnet Config
:HUBCONFIG
D:
CDMYSTIC
start MYSTIC -CFG
IF ERRORLEVEL 1 GOTO Error
GOTO MENU
;Fidopoll Force FSXNet Hub
:FORCEHUB
D:
CDMYSTIC
START FIDOPOLL FORCED
IF ERRORLEVEL 1 GOTO Error
GOTO MENU
;Load Standard MIS for FSXHub
:MISHUB
D: 
CDMYSTIC
start mystickeep.bat
IF ERRORLEVEL 1 GOTO Error
goto menu
;Load MIS II for FSXHub
:MIS2HUB
D:
CDMYSTIC
start MIS2 SERVER
IF ERRORLEVEL 1 GOTO Error
goto menu
:Error
ECHO OFF
Type c:MYSTICERROR.ANS
ECHO off
PAUSE
GOTO Menu
;End DosMenu script

'

我根本不打算深入研究你的代码,所以我在这里给出一个更短的版本。

首先,看到我使用了setlocal enableddelayedexpansion并且不打算解释所有内容,因为如果您从cmdline运行,则有很多信息setlocal /?另请注意,我添加了无输入标签。这意味着如果没有添加任何输入,它将跳到该部分,该部分会播放一条消息,为什么它返回提示。

@echo off
setlocal enabledelayedexpansion
goto MENU
:NOINPUT
cls
echo You have not typed in a valid selection.
:MENU
echo Please enter a choice:
SET /P "M=select 1 to 22"
set var=%M%
IF !var!==1 GOTO OPTION1
IF !var!==2 GOTO OPTION2
IF "!var!"==""  GOTO NOINPUT
:OPTION1
echo this is option 1
pause
exit
:OPTION2
echo this is option 2
exit

最新更新