Windows Command Line

Posted by Markus O'Reilly on Stack Overflow See other posts from Stack Overflow or by Markus O'Reilly
Published on 2010-03-13T02:42:01Z Indexed on 2010/03/13 2:47 UTC
Read the original article Hit count: 380

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about command-line

Related posts about loops