Windows 命令行
有谁知道直接在 Windows 命令行中输入 for 循环时如何打破它?我知道当它在批处理文件中时,您可以使用 goto 和标签来打破它,但我在命令行上找不到任何有关打破它的信息。这是一个简单的例子:
C:> for /l %i in (1,0,1) do @ping -n 1 google.com || (echo ^G & msg user "Google is down!" & QUIT)
这应该无限地 ping google.com。如果失败,它会发出蜂鸣声(回显 ^G),向用户“user”显示一个消息框,提示“Google 已关闭!”,然后退出。但我不知道如何执行退出部分。我想我可以做类似 taskkill /f /im cmd.exe 的事情,但我一直在寻找更优雅的东西。有什么建议吗?
Does anyone know how to break out of a for loop when it's typed directly into the windows command-line? I know you can use gotos and labels to break out of it when it's in a batch file, but I can't find anything about breaking out of one on the command line. Here's a simple example:
C:> for /l %i in (1,0,1) do @ping -n 1 google.com || (echo ^G & msg user "Google is down!" & QUIT)
This should infinitely ping google.com. If it ever fails, it beeps (echo ^G), displays a message box to the user "user" that says "Google is down!", and QUITs. I don't know how to do the quit part though. I guess I could do something like taskkill /f /im cmd.exe, but I was looking for something more elegant. Any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其包装到
cmd
的另一个实例中并使用exit
:Wrap it into another instance of
cmd
and useexit
:尝试
退出
而不是退出Try
Exit
instead of Quit