Windows's Snipping tool can capture the screen, but sometimes I want to capture the screen after five seconds, such as taking an image being displayed by the webcam. (Run the script and smile at the camera, for example.)
How do I sleep for 5 seconds in a batch file?
Type in your command. TIMEOUT — Type timeout time where "time" is replaced by the number of seconds to delay. For example, typing in timeout 30 will delay your batch file for 30 seconds.
F3: Repeat the previous command. Up/Down Arrow: Scroll backward and forwards through previous commands you've typed in the current session.
I'm very surprised no one has mentioned:
C:\> timeout 5
N.B. Please note however (thanks Dan!) that timeout 5
means:
Sleep anywhere between 4 and 5 seconds
This can be verified empirically by putting the following into a batch file, running it repeatedly and calculating the time differences between the first and second echo
s:
@echo off echo %time% timeout 5 > NUL echo %time%
One hack is to (mis)use the ping command:
ping 127.0.0.1 -n 6 > nul
Explanation:
ping
is a system utility that sends ping requests. ping
is available on all versions of Windows.127.0.0.1
is the IP address of localhost. This IP address is guaranteed to always resolve, be reachable, and immediately respond to pings.-n 6
specifies that there are to be 6 pings. There is a 1s delay between each ping, so for a 5s delay you need to send 6 pings.> nul
suppress the output of ping
, by redirecting it to nul
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With