batch-file - 用户输入后意外退出

标签 batch-file

我的代码需要一些帮助。

当脚本检测到保存文件时,它需要询问是否重新创建它。此时,我点击Y表示,但它退出

代码如下:

:existing
echo Welcome to Androids: Became Human!
echo ==================================
echo.
echo It appears that you already created
echo configuration file. Would you like
echo to re-create it?
echo.
echo Please enter (Y,N):
set /p choice=
if %choice% == "y" goto welcome
if %choice% == "n" exit
if %choice% == "Y" goto recreation
if %choice% == "N" exit

最佳答案

两边都使用引号,下面是一个示例:

不好:

:existing
echo Welcome to Androids: Became Human!
echo ==================================
echo.
echo It appears that you already created
echo configuration file. Would you like
echo to re-create it?
echo.
echo Please enter (Y,N):
set /p choice=
if %choice% == "y" goto welcome
if %choice% == "n" exit
if %choice% == "Y" goto recreation
if %choice% == "N" exit

好:

:existing
echo Welcome to Androids: Became Human!
echo ==================================
echo.
echo It appears that you already created
echo configuration file. Would you like
echo to re-create it?
echo.
echo Please enter (Y,N):
set /p choice=
if "%choice%" == "y" goto welcome
if "%choice%" == "n" exit
if "%choice%" == "Y" goto recreation
if "%choice%" == "N" exit

此外,我还为您的代码制作了更好的版本:

:existing
echo Welcome to Androids: Became Human!
echo ==================================
echo.
choice /c ynY /cs /m "It appears that you already created the configuration file, would you like to save it"
cls
if "%errorlevel%" == "1" goto welcome
if "%errorlevel%" == "2" exit
if "%errorlevel%" == "3" goto recreation

关于batch-file - 用户输入后意外退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54833497/

相关文章:

for-loop - 如何在批处理文件中执行此 CMD 脚本?

windows - 如何从 Windows Batch 子程序调用 SCons?

math - 批处理文件中是否存在 "Power to"函数? (指数)

windows - 如何使用 Windows 批处理文件删除不包含某些字符的文件?

batch-file - 我如何知道磁盘是否为 SSD?

windows - 检查 Web 服务器并且不从同一服务器上的配置文件解析端口 80 和端口 8080

node.js - NSSM 未启动简单服务

java - 使用 Java 进行命令行版本控制——处理大量嵌套目录

batch-file - 如何使用批处理文件单击按钮?

windows - 如何在批处理文件中执行多个 git 命令而不在第一个命令后终止?