0

I am creating a wait program using batch, but when I try to insert the 3 seconds delay using ping :

ping ::1 -n 3 >nul 2>nul

Only waits 2 seconds. Why does this happen?

Gerhard
  • 18,114
  • 5
  • 20
  • 38
KyLeCoOl
  • 27
  • 3
  • 2
    Keep in mind, ping is not a timer. `-n` is number of replies required. Your first ping is on execution, 1 second to the second ping, 1 second to the last ping. making it two seconds. Why not instead use `timeout 3 /nobreak >nul 2>&1` – Gerhard Oct 22 '19 at 06:40
  • note that ping is not a good way for delaying. There are many better tools [How to sleep for five seconds in a batch file/cmd](https://stackoverflow.com/q/1672338/995714) – phuclv Oct 22 '19 at 08:11
  • @phuclv Yes, I know, but I was just experimenting. Doesn't hurt to find out new things :) – KyLeCoOl Dec 28 '19 at 10:35

1 Answers1

2

Because it makes its first ping without a delay (on execution). three pings means 2 delays. If you like to have a delay of 3 seconds, you need to ping 4 times.

Gerhard
  • 18,114
  • 5
  • 20
  • 38
Gerrit
  • 133
  • 1
  • 9