Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ping Errorlevel

Status
Not open for further replies.

DaveNamou

IS-IT--Management
Feb 7, 2002
175
0
0
US
Can anyone tell me why the following script does not work? It's supposed to return an ErrerLevel of 1 if ping returns "Request timed out". But instead, it always returns "Errorlevel 0". ???


@Echo Off
:start
ping 192.168.0.1
If ErrorLevel==1 Echo Error 1
If ErrorLevel==0 Echo Error 0
goto start


Any Ideas? Dave Namou, MCSE CCEA
 
i think it is how ping sets the errorlevel. what i have seen done is to pipe that output to FIND and check errorlevel off that. something like this maybe:

ping 192.168.0.1 | find "TTL=" > NUL

if %errorlevel% == 0 echo "error 0"
if %errorlevel% == 1 echo "error 1"


that might help. doesn't answer your original question but i think it'll help
 
I found this sample script to help. It's Kinda like what your talking about with the find command.

@echo off
ping 192.168.0.1 | find "Reply" > nul
if not errorlevel 1 echo Success


The errorlevel is actually being set by the find command.

=So if the word "Reply" exists in the result of Ping, then the errorlevel is 0.
=If the word does not exist, then Errorlevel 1 is also raised. Note that Errorlevel 0 is still set as well. Dave Namou, MCSE CCEA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top