batch-file

How do I make an If event in batch when a ping fails?


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?


Solution

  • Try like this :

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

    for more explaination :

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