如何在批处理文件/cmd中睡眠五秒钟 [英] How to sleep for five seconds in a batch file/cmd

查看:165
本文介绍了如何在批处理文件/cmd中睡眠五秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows的Snipping工具可以捕获屏幕,但是有时我想在五秒钟后捕获屏幕,例如拍摄网络摄像头显示的图像. (例如,运行脚本并对着镜头微笑.)

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.)

如何在批处理文件中睡眠5秒钟?

How do I sleep for 5 seconds in a batch file?

推荐答案

一种技巧是(mis)使用ping命令:

One hack is to (mis)use the ping command:

ping 127.0.0.1 -n 6 > nul

说明:

  • ping 是一种用于发送ping请求的系统实用程序. ping在所有版本的Windows上均可用.
  • 127.0.0.1 localhost 的IP地址.该IP地址保证始终解析,可访问并立即响应ping.
  • -n 6指定要进行6次ping.每次ping之间有1秒的延迟,因此,如果要延迟5s,则需要发送6次ping.
  • > nul通过重定向到 nul .
  • 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.

这篇关于如何在批处理文件/cmd中睡眠五秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆