I was happily using ping 0. Show 4 more comments. Windows ping pauses for one second between pings so you if you want to sleep for 10 seconds, use ping -n 11 Gleb Gleb 2, 1 1 gold badge 12 12 silver badges 7 7 bronze badges. I like this solution more than the the one marked as the answer because this is cleaner as we don't have to make sure that our script has a non-existent IP address. Therefore, we can write the script once and use it on any Windows system in any network without editing the script again.
Since RFC became obsoleted I'm using this solution. Or perhaps use localhost to avoid problems on IPv6-only machines. Also not a Windows XP command Now that WindowsXP is on the way out, it seems like this is really the way to do it in the future. This may not have been the correct answer for XP in but it is for Windows 7 and above! In , this should become the correct answer. Show 1 more comment. Lee Lee. Its in fact better than sleep. It tells time remaining!
It works on Windows and Windows 7 though. ItayLevin: the unit is seconds. Chakrit's answer gives you another way to pause, too. Try running sleep 10 from a command prompt. Peter Mortensen The Overflow Blog. Facebook Twitter Instagram. TecAdmin Home Ubuntu Related Posts. Which Process is listening on a Port in Windows? Updated: October 28, 2 Mins Read. Chris Owen on October 17, am. So far, using sleep.
This is the latest version of what I am using in practice for a ten second pause to see the output when a script finishes. The echo done allows me to see when the script finished and the ping provides the delay. The extra signs mean that I see the "done" text and the waiting occurs without me being distracted by their commands. I have tried the various solutions given here on an XP machine, since the idea was to have a batch file that would run on a variety of machines, and so I picked the XP machine as the environment likely to be the least capable.
This seemed to give a three second delay as expected. One ping attempt lasting a specified 3 seconds.
This took around 10 seconds not 5. My explanation is that there are 5 ping attempts, each about a second apart, making 4 seconds. And each ping attempt probably lasted around a second making an estimated 9 seconds in total. I tried the above too, after reading that comments could be added to BAT files by using two consecutive colons. However the software returned almost instantly.
Putting the comment on its own line before the ping worked fine. My explanation is that there are 5 ping attempts each lasting 5 seconds, but there is about a 1 second time delay between ping attempts: there is after all little reason to expect a different result if you ping again immediately and it is better to give a network a little time to recover from whatever problem it has had.
Edit: stolen from another post ,.. RFC says the IP address I have modified the text above accordingly! I made this. It is working and show time left in seconds. If you want to use it, add to a batch file:.
Listing of wait. An improvement of the code proposed by the user Aacini, It has resolution of hundredths of a second and does not fail when the time reaches , You can use VBScript , for example, file myscript. I use the following method entirely based on Windows XP capabilities to do a delay in a batch file:. You may also insert the day in the calculation so the method also works when the delay interval pass over midnight. Download the Sleep.
It can be done with two simple lines in a batch file: write a temporary. If you have an appropriate version of Windows and the Windows Server Resource Kit Tools , it includes a sleep command for batch programs.
EDIT: You should also be away that if the machine isn't connected to a network say a portable that your using in the subway , the ping trick doesn't really work anymore. That is, unless you tell it to only wait for 1 second before timing out.
I wrote a powerbasic program wait. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 12 years, 2 months ago. Active 1 year, 6 months ago. Viewed 2. Improve this question. Peter Mortensen Refs: SS64 , Rob van der Woude. There is timeout command that waits for seconds. In case if millisecond sleep is needed, powershell's Start-Sleep can be used.
To sleep 50ms in cmd: powershell Start-Sleep -m 50 — Pavel P. Pavel: You can also misuse a ping to a non-existent host to sleep for milliseconds.
A good summary of the various techniques to halt a batch file process: robvanderwoude. Show 2 more comments. Active Oldest Votes. Please note however thanks Dan! Improve this answer.
Evgeniy Berezovsky Timeout is poorly implemented. If you do a "timeout 1", it will wait until the "next second," which could occur in. Try doing "timeout 1" a few times and observe the difference in delay. For 5 seconds or more, it may not be a big deal, but for a 1 second delay it works poorly.
Show 20 more comments. One hack is to mis use the ping command: ping This IP address is guaranteed to always resolve, be reachable, and immediately respond to pings. There is a 1s delay between each ping, so for a 5s delay you need to send 6 pings. MultiplyByZer0 4, 3 3 gold badges 29 29 silver badges 46 46 bronze badges. Martin Martin This doesn't work well for me could be a networking issue? When I try the above command without the pipe to nul I immediately get a "Destination host unreachable" from the gateway server and the ping command exits straight away.
It's cleaner and more reliable, IME, to do "ping One correction - 1. Theoretically, it may be reached. It's offline now because I suspect their owners gave up hope to use it for anything but pings from all over the world : For more details on this IP see serverfault. It's saver to either use Cybergibbons Beware fence-post error here. There is a 1s delay between each ping, so for a 10s delay you need to do 11 pings, i. II recommend to use Show 12 more comments.
Default list is "YN". The message before the prompt is displayed and the choices are still enabled. By default, the utility is case-insensitive. Acceptable values are from 0 to If 0 is specified, there will be no pause and the default choice is selected.
If not specified, the utility displays only a prompt. Displays this help message. The first choice listed returns a value of 1, the second a value of 2, and so on.
0コメント