我编写了以下代码
choice /m "Do you want to add another profile"
if errorlevel 1 set /p profile_name1=Enter one of the above profile names:但是,它总是运行“输入上述配置文件名称之一:”,即使我按了“no”。我做错什么了?
谢谢!
发布于 2009-10-25 10:37:58
您需要为每个结果提供说明。例如:
choice /m "Do you want to add another profile"
if errorlevel 2 goto :doOtherStuff
if errorlevel 1 set /p profile_name1=Enter one of the above profile names:
:doOtherStuff另请注意,顺序很重要,您必须以降序(2和1)列出错误级别。
发布于 2009-10-25 09:55:11
首先,/m不是可以传递给choice的有效参数。试着去掉它,它可能会让人困惑。
此外:如果返回代码等于或高于指定的错误级别,则IF ERRORLEVEL返回TRUE。尝试检查每个可能的返回值(在您的示例中,均为yes和no)
IF ERRORLEVEL 2 SET ANS="No"
IF ERRORLEVEL 1 SET ANS="Yes"并在批处理文件的其余部分中使用ANSwer的值。
https://stackoverflow.com/questions/1619722
复制相似问题