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

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

问题描述

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

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?

推荐答案

一个 hack 是(误)使用 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.1localhost 的 IP 地址.此 IP 地址可保证始终解析、可访问并立即响应 ping.
  • -n 6 指定有 6 个 ping.每次 ping 之间有 1 秒的延迟,因此对于 5 秒的延迟,您需要发送 6 次 ping.
  • <代码>>nul 抑制 ping 的输出,通过 重定向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天全站免登陆