Use the SysSleep function whenever you need a time delay in Rexx scripts. Use the Sleep command for time delays in KiXtart scripts. Use WScript. The following batch code uses a temporary VBScript file to generate an accurate delay:. Or if you want to allow the user to skip the delay:. ECHO Wait for a specified number of seconds. ECHO Where: seconds is the number of seconds to wait ECHO The delay time will not be very accurate. ECHO Backup has been skipped.
Click a script file name to expand and view its source code; click the file name again, or the expanded source code , to hide the source code again. Save my name, email, and website in this browser for the next time I comment. Facebook Twitter Instagram. TecAdmin Home Ubuntu Related Posts. Which Process is listening on a Port in Windows? Updated: October 28, 2 Mins Read. Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Connect and share knowledge within a single location that is structured and easy to search. The correct way to sleep in a batch file is to use the timeout command, introduced in Windows To wait somewhere between 29 and 30 seconds :. Additionally, if you don't want the command to print its countdown on the screen, you can redirect its output to NUL :.
Since it applies here, too, I'll copy my answer from another site. If you want to use ping, there is a better way. You'll want to ping an address that does not exist, so you can specify a timeout with millisecond precision.
Luckily, such an address is defined in a standard RFC , and it is This is not made-up, it really is an address with the sole purpose of not-existing it may not be clear, but it applies even in local networks :.
It is often used in conjunction with domain names example. Addresses within this block should not appear on the public Internet. To sleep for milliseconds, use ping You can also insert a ping to localhost. This will take 4 seconds to complete by default. It is considered a kludge by some, but works quite well all the same. Disclaimer : this is not the "ideal" solution, so don't bother beating me over the head with that like done to those recommending ping When possible, use timeout for sure.
But as noted in the comments, that's not always an option e. After that, I agree that the ping "kludge" is perhaps the next best option, as it is very simple. That said, I offer another option The basis of this solution has all sorts of application beyond this. Often VBS can do things that batch cannot, or at the very least do so with drastically more ease.
Using the technique illustrated here, you can mix the two not "seamlessly", but "functionally" Here's a one liner, to create a temp script, execute it, then delete it.
The script does the sleeping for you for 3 seconds in this example. And then finally, like ping , CScript itself has a timeout option! So, if you enter an infinite loop in the script, you can let the interpreter enforce the duration. Note, this is a "busy" operation, which eats the CPU, and therefore I don't recommend it when you can use the WScript.
Sleep procedure, but I present it as a conceptual option for the sake of completeness:. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
0コメント