北斗神拳世界结局:DOS批处理如何判断是否继续执行

来源:百度文库 编辑:高校问答 时间:2024/04/30 02:43:54
想写一个DOS批处理文件,在执行命令前提示按“Y”键执行 按“N”键放弃执行
楼下的答案小弟看不懂,
我要解决的问题是这样的:

@Echo 真的要停止服务吗?
@Echo 按任意键停止服务.... 取消操作请直接关闭本窗口

@Pause >nul
@Echo Off
net stop 辅助服务
net stop 数据服务

我想把上面的第二行改成
@Echo 按‘Y’键停止服务.... 按‘N’键取消

需要怎么写这个文件呢?

用set命令应该可以满足你的要求:

@Echo Off
Echo 真的要停止服务吗?

:again
set /p yn=按'Y'键停止服务.... 按'N'键取消:
if %yn%==y goto cont
if %yn%==Y goto cont
if %yn%==n goto end
if %yn%==N goto end
echo "输入错误,请重新输入!"
goto again

:cont
net stop 辅助服务
net stop 数据服务

:end

@echo off
choice /yn yes,no
if errorlevel 2 goto yes 应先判断数值最高的错误码
if errotlevel 1 goto no
:yes
..........
:no
.......

看不懂就没辙了