解决方案

解决方案

我正在编写一个小程序来更新它的配置,我是批处理脚本的新手,
用户需要输入所需的输入才能进入所需的程序,我在批处理文件中有 5 组程序,如果用户没有输入任何数字并按下回车键,我不知道如何设置程序,在这种情况下我需要开始

:begin
SET /P runscript="Press The Desired Key and Press Enter ="
if %runscript%==1 goto setup
if %runscript%==2 goto start
if %runscript%==3 goto show
if %runscript%==4 goto stop
if %runscript%==5 goto end

我怎样才能做到这一点?

答案1

解决方案

首先,您应该确保runscript变量为空,然后检查它是否实际定义:

:begin
set runscript=
set /p runscript="Press The Desired Key and Press Enter ="
if not defined runscript goto :begin

if %runscript% == 1 goto :setup
if %runscript% == 2 goto :start
if %runscript% == 3 goto :show
if %runscript% == 4 goto :stop
if %runscript% == 5 goto :end

进一步阅读

相关内容