首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按Enter键时,DOS批处理菜单进入错误级别1。

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

Stack Overflow用户
提问于 2017-11-15 12:28:37
回答 1查看 833关注 0票数 1

我已经为我的BBS和Echomail集线器制作了DOS批处理菜单。原始版本不包含任何错误级别的行,当用户按enter时,批处理将崩溃为提示。我向每个GOTO组添加了错误级别的行,现在当用户按enter时,它会转到错误屏幕,在那里按enter再次将用户带回主菜单,而不是崩溃为提示符。当用户按enter时,除了显示错误屏幕之外,没有其他命令,因此必须有一种更干净的方法来“循环”回主菜单。我在这里进行了研究,发现了其他批处理菜单的“报价”修复,但这根本不起作用,并使巴赫功能失效。这是我批次的副本。主要关注:在没有其他命令的情况下按回车时如何循环巴赫到菜单。谢谢

代码语言:javascript
复制
ECHO OFF
:menu
CLS
Type c:\MYSTIC\DOSMENU.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:
cd\mystic
start mutil nodelists
IF ERRORLEVEL 1 GOTO Error
goto menu

;Purge all Old EchoMail
:purge
c:
cd\mystic
start mutil purge
IF ERRORLEVEL 1 GOTO Error
GOTO Menu 

;Process mailin Mutil 
:mailin
c:
cd\mystic
start mutil mailin
IF ERRORLEVEL 1 GOTO Error
GOTO Menu 

;Backup BBS and Hub
:back
c:
cd\mystic
start mysticbu
IF ERRORLEVEL 1 GOTO Error
goto menu

;Load Netrunner
:netrunner
c:
cd\nr20b18w
start netrunner.exe
IF ERRORLEVEL 1 GOTO Error
goto menu 

;Kill all Busy nodes
:kill
cd\
c:
cd\mystic
start fidopoll killbusy
IF ERRORLEVEL 1 GOTO Error
GOTO Menu

;Gernerate Top Callers Report
:TOP
c:
CD\Mystic
START fidopoll killbusy
IF ERRORLEVEL 1 GOTO Error
GOTO Menu

;Forced Fidopoll of all Nodes on the BBS
:Fidopoll
c:
cd\mystic
start fidopoll forced
IF ERRORLEVEL 1 GOTO Error
goto menu


;Load DOSBox
:BOX
c:
Cd\PROGRAM FILES (x86)\DOSBOX-0.74\
start DOSBOX
IF ERRORLEVEL 1 GOTO Error
GOTO MENU 

;Start BBS Config Program
:fig
c:
cd\mystic
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:
CD\MYSTIC
start mystickeep.bat
IF ERRORLEVEL 1 GOTO Error
GOTO MENU 

;Start Mystic internet server II BBS
:MIS2404
c:  
CD\MYSTIC
start MIS2 SERVER
IF ERRORLEVEL 1 GOTO Error
GOTO MENU 

;Start Standard MIS for the file server
:MIS606
c:
CD\mysticfs
START MIS
IF ERRORLEVEL 1 GOTO Error
GOTO MENU

;Start MIS II for the file Server
:MIS2606
c: 
CD\MysticFS
START MIS2 SERVER
IF ERRORLEVEL 1 GOTO Error
GOTO Menu

;Load Mystic Relay Chat
:MRC 
c:
CD\MYSTIC
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:
CD\MYSTIC
start MYSTIC -CFG
IF ERRORLEVEL 1 GOTO Error
GOTO MENU

;Fidopoll Force FSXNet Hub
:FORCEHUB
D:\
CD\MYSTIC
START FIDOPOLL FORCED
IF ERRORLEVEL 1 GOTO Error
GOTO MENU

;Load Standard MIS for FSXHub
:MISHUB
D: 
CD\MYSTIC
start mystickeep.bat
IF ERRORLEVEL 1 GOTO Error
goto menu

;Load MIS II for FSXHub
:MIS2HUB
D:\
CD\MYSTIC
start MIS2 SERVER
IF ERRORLEVEL 1 GOTO Error
goto menu

:Error
ECHO OFF
Type c:\MYSTIC\ERROR.ANS
ECHO off
PAUSE
GOTO Menu

;End DosMenu script

`

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-15 13:02:58

我根本不会钻研您的代码,所以我将在这里给出一个更短的版本。

首先,请注意我使用的是setlocal enableddelayedexpansion,而不是所有的解释,因为如果您从cmdline setlocal /?运行,那么会有很多信息,还注意到我添加了no输入标记。这意味着,如果没有添加的输入,它将跳到该部分,这部分广告将消息为什么返回到提示符。

代码语言:javascript
复制
@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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47307442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档