0

I know this has been asked many times before but it's a bit different in my situation.

"If errorlevel 1" does not work in my case

When I ping something like my router when my ethernet is unpluged than it won't return a "timeout" it will return a "general failure" the statement "if errorlevel 1" won't detect it so I'm getting a response saying that it's reachable when it's not and it won't detect the "general failure" as an error.

I was thinking maybe it's possible to make a line checking the response (in ascii) to check if it's "General Failure" but I wouldn't know how to do that either.

Is there a way to get past this problem or is this the limit of batch?

Shayna
  • 334
  • 5
  • 17

1 Answers1

2

Try like this :

ping "www.whatever.com" && echo OK || echo Connection Problem

for more explaination :

http://www.robvanderwoude.com/condexec.php

SachaDee
  • 9,245
  • 3
  • 23
  • 33
  • What is the `&&` and `||` priority? Statements like these always confuse me because of the lack of parenthesis. – Blue Oct 18 '16 at 14:46
  • There is no priority. The statement after `&&` will be displayed if the errorlevel is [<= 0] and the statement after `||` will be displayed if the errorlevel [>=1]. You can also use parenthesis if you will do more think. `ping "www.whatever.com" && (do what you want) || (do what you want)` – SachaDee Oct 18 '16 at 14:49
  • This does not work in all cases. Please, read [this](http://stackoverflow.com/a/27748080/2861476) – MC ND Oct 18 '16 at 14:51