gpt4 book ai didi

batch-file - 如何在批处理脚本中等待?

转载 作者:行者123 更新时间:2023-12-03 04:19:35 25 4
gpt4 key购买 nike

我正在尝试编写批处理脚本并尝试在 2 个函数调用之间等待 10 秒。命令:

sleep 10

不让批处理文件等待 10 秒。

我运行的是 Windows XP。

注意:这不是 Sleeping in a batch file 的完整副本。因为另一个问题也与 python 相关,而这是关于 Windows 批处理文件。

最佳答案

您可以 ping 不存在的地址并指定所需的超时:

ping 192.0.2.2 -n 1 -w 10000 > nul

由于该地址不存在,它将等待 10,000 毫秒(10 秒)并返回。

  • -w 10000 部分指定所需的超时(以毫秒为单位)。
  • -n 1 部分告诉 ping 它应该只尝试一次(通常会尝试 4 次)。
  • 附加 > nul 部分,以便 ping 命令不会向屏幕输出任何内容。

您可以通过在 PATH 中的某个位置创建 sleep.bat 并使用上述技术来轻松地自己创建 sleep 命令:

rem SLEEP.BAT - sleeps by the supplied number of seconds

@ping 192.0.2.2 -n 1 -w %1000 > nul
<小时/>

注意(2020 年 9 月): 192.0.2.x 地址根据 RFC 3330 保留。所以现实世界中绝对不会存在。引用规范:

192.0.2.0/24 - This block is assigned as "TEST-NET" for use indocumentation and example code. It is often used in conjunction withdomain names example.com or example.net in vendor and protocoldocumentation. Addresses within this block should not appear on thepublic Internet.

关于batch-file - 如何在批处理脚本中等待?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/735285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com