How to sleep for five seconds in a batch file/cmd
Posted By: Anonymous
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?
Solution
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 ofping
, by redirecting it tonul
.
Answered By: Anonymous
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.