本文介绍了是/否批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的批处理文件中,我想问用户一个问题.
In my batch file I want to ask the user a question.
我写了以下内容:
SET /P ANSWER=Click Y to continue or N to stop (Y/N)但是我收到的消息没有最后一个).
but I get the message without the last ).
有人知道为什么吗?
谢谢!
推荐答案因为您正在括号内的提示中使用该提示,例如
Because you're using that prompt within a parenthesised block, e.g.
if ... ( ... set /P ANSWER=Blah (Y/N) )或
for %%x in (...) do ( ... set /P ANSWER=Blah (Y/N) )在这种情况下,您必须转义右括号:
You have to escape the closing parenthesis in that case:
SET /P ANSWER=Click Y to continue or N to stop (Y/N^)或引用整个参数:
SET /P "ANSWER=Click Y to continue or N to stop (Y/N)"否则它将关闭该块.而且,如果在结束括号后还有其他内容,则会出现语法错误.
otherwise it closes the block. And if you had anything after that closing parenthesis you'd get a syntax error.
一种更简单的操作方法可能是choice命令:
An easier method of what you do there would probably be the choice command:
choice /M "Press Y to continue or N to stop" /c YN然后您可以随后检查错误级别以找出用户的选择:
You can then check the errorlevel afterwards to find out the user's choice:
if errorlevel 255 ( echo Error ) else if errorlevel 2 ( echo No. ) else if errorlevel 1 ( echo Yes. ) else if errorlevel 0 ( echo Ctrl+C pressed. )更多推荐
是/否批处理文件
发布评论