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.
ping -n 3 192.168.0.4 >nul: 2>nul:
if %ERRORLEVEL% EQU 0 (
) else (
echo not ok