07-23-2023, 07:46 AM
When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of it [here][1], which describes a callable "wait.bat", implemented as follows:
@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n %1% -w 1000> nul
You can then include calls to wait.bat in your own batch file, passing in the number of seconds to sleep.
[Apparently the Windows 2003 Resource Kit provides a Unix-like sleep command][2] (at last!). In the meantime, for those of us still using Windows XP, Windows 2000 or (sadly) [Windows NT][3], is there a better way?
I modified the `sleep.py` script in the [accepted answer][4], so that it defaults to one second if no arguments are passed on the command line:
<!-- language: python -->
import time, sys
time.sleep(float(sys.argv[1]) if len(sys.argv) > 1 else 1)
[1]:
@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n %1% -w 1000> nul
You can then include calls to wait.bat in your own batch file, passing in the number of seconds to sleep.
[Apparently the Windows 2003 Resource Kit provides a Unix-like sleep command][2] (at last!). In the meantime, for those of us still using Windows&nbsp;XP, Windows 2000 or (sadly) [Windows NT][3], is there a better way?
I modified the `sleep.py` script in the [accepted answer][4], so that it defaults to one second if no arguments are passed on the command line:
<!-- language: python -->
import time, sys
time.sleep(float(sys.argv[1]) if len(sys.argv) > 1 else 1)
[1]:
[To see links please register here]
[2]:[To see links please register here]
[3]:[To see links please register here]
[4]:[To see links please register here]