Windows批处理在错误的变量上关闭. [英] Windows batch closes on wrong variable.

查看:155
本文介绍了Windows批处理在错误的变量上关闭.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!我知道有一个简单的方法可以做到这一点.我不知道怎么.有人可以帮我解决这个问题吗?
当我有一个/p变量并且用户输入了错误的变量时,如何阻止它关闭
可以说我有:
set/p a =选择一个选项:
而这两个选项是启动和退出.
他们说
选择一个选项:退出
不好了!命令提示符关闭!
我找不到解决方案,有人可以帮忙吗?
________________________________________________________________________
记住帮助"!

Hello! I know there is a simple way to do this. I do not know how. So can someone help me with this question:
When i have a /p variable and the user enters the wrong variable how can i stop it from closing
Lets say i have:
set /p a=Choose a option:
And the two options are start and quit.
they say
Choose a option: quitt
Oh no! Command prompt closes!
I cannot find a solution can anyone help?
________________________________________________________________________
Remember "help"!

推荐答案

代码可能是这样的:
The code could be something like this:
@echo off
set /p var=Choose a option ('s' to start, 'q' to quit):
if %var%==q goto:eof
echo working!



在此示例中,如果您输入"q",则正在工作!"将不会打印,因为您转到了脚本的末尾.您还可以将功能与批处理文件(!)一起使用.请查看我最近的答案:
批量变量方程 [

—SA



In this sample, if you enter ''q'', "working!" will not be printed, because you go to the end of the script. You also can use functions with batch files (!). Please see my recent answer:
Batch variable equations[^].

Chances are, your code already works correctly; but you probably you haven''t started command interpreted, so it was not closed, but the console of you batch was closed. If you started it with CMD.EXE and then started your batch from the command line. Or, alternatively, start it with "CMD /K your_script_batch". Again, please see the help created by the script I referenced in my previous answer.

—SA


这篇关于Windows批处理在错误的变量上关闭.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆