Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running this within windows xp batch file:

ping -n 3 >nul: 2>nul:
if %errorlevel%==0 (
    echo ping reply arrived        
) else (
    echo no ping reply.

sometime, it seems like i get no ping reply although on a parallel cmd line window running

ping -t

Am I checking in a wrong way?

share|improve this question

Perhaps reconsider why you are testing connectivity (I assume that is what you are doing?) this way. Ping is not a reliable method of determining a hosts connectivity:

  • Ping is ICMP and can have different results on different network devices and is therefore not always guaranteed to react the same way
  • It could be being rate limited and therefore occasionally return no results
  • Dropped packets, latency, or general packet loss can cause a ping to not return; it can even be dropped by QoS
  • Ping describes nothing about the routing environment or any problems other than end to end/host

Perhaps reconsider what you are trying to do? If you give us more information I'm sure we can offer some more reliable suggestions.

EDIT: The following batch script works for me.

@echo off
ping -n 3 >nul: 2>nul:
    echo ok
) else (
    echo not ok
share|improve this answer
I have two systems connected via network switch in a closed environment. I want to check if system B is reachable over network from system A. I also want to check if network connectivity exists(eth cable in place etc.) – Doron Jan 19 '12 at 11:16
Could you please say if "ping -n 3 >nul: 2>nul:" and then checking the errorlevel is correct? – Doron Jan 19 '12 at 11:17
Hmm, ping does seem like the way to go then. In my experience it is impossible to have 100% success return rate on pings, no matter the environment (you should see this reflected in your -t, as well). In that case your best bet is going to be checking for consecutive ping failures or the availability of a service on the the host (http, ssh, telnet, etc). – Josh Atkins Jan 19 '12 at 11:19
is this syntax correct ">nul: 2>nul:"? How could I check for an available service on the host, for example? – Doron Jan 19 '12 at 11:22
Yep, that syntax is correct. I updated my original answer with a scrpit that works for me, the only different is using EQU instead of == (my batch is pretty weak, I don't know offhand if there is a difference). The casing of ErrorLevel should also be irrelevant. – Josh Atkins Jan 19 '12 at 11:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.