I'm using the windows batch script function ping 192.0.2.2 -n 1 -w 10000 > nul on my local machine (Windows 7) in a command prompt to test its functionality. The explanation of the function is here: "How to wait in a batch script?".
I've used 192.0.2.2 because it is considered a reserved IP address, so there should be no response. But instead, my results are inconsistent - sometimes I get a response with the error "Destination net unreachable."
C:\Users\MrF>ping 192.0.2.2 -n 1 -w 10000
Pinging 192.0.2.2 with 32 bytes of data:
Reply from 10.10.251.2: Destination net unreachable.
Ping statistics for 192.0.2.2:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
C:\Users\MrF>ping 192.0.2.2 -n 1 -w 10000
Pinging 192.0.2.2 with 32 bytes of data:
Request timed out.
Ping statistics for 192.0.2.2:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
C:\Users\MrF>ping 192.0.2.2 -n 1 -w 10000
Pinging 192.0.2.2 with 32 bytes of data:
Request timed out.
Ping statistics for 192.0.2.2:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
C:\Users\MrF>ping 192.0.2.2 -n 1 -w 10000
Pinging 192.0.2.2 with 32 bytes of data:
Request timed out.
Ping statistics for 192.0.2.2:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
C:\Users\MrF>ping 192.0.2.2 -n 1 -w 10000
Pinging 192.0.2.2 with 32 bytes of data:
Reply from 10.10.251.2: Destination net unreachable.
Ping statistics for 192.0.2.2:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
C:\Users\MrF>ping 192.0.2.2 -n 1 -w 10000
Pinging 192.0.2.2 with 32 bytes of data:
Request timed out.
Ping statistics for 192.0.2.2:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
C:\Users\MrF>
Unfortunately, the function only waits 10 seconds when the ping is lost. Pings that receive a response don't wait at all. This has lead to some frustrating lack of functionality in my scripts that require wait commands. How can I fix this? Why is it happening?