windows - 如何在 Windows 批处理文件中的 HH:29:55 和 HH:59:55 触发命令
问题描述
在 Windows 批处理文件 (x.bat) 中,当时间的第二部分大于 55 时,如何每 30 分钟触发一次命令?
我现在拥有的是:
:loop
program.exe
PING localhost -n 1800 >NUL
goto loop
问题是时间不够精确,即。秒 > 55 在 min%30==29。
解决方案
如前所述,任务计划程序能够胜任这项任务。它可以每天运行一次,每 30 分钟一次,从next hour:59:55
也就是说,有一些方法可以编写这些内容。这不是最强大的解决方案,但它确实有效。
@echo off
:start
for /f %%i in ('powershell Get-Date -Format mm:ss') do (
if "%%i"=="29:55" program.exe
if "%%i"=="59:55" program.exe
timeout 1 /nobreak>nul
)
goto start
推荐阅读
- css - 有没有办法让 div 的高度设置为`overflow-y: auto`
- python - 将 Heroku 一次性测功机作为 `:detached` 运行会导致它消耗更多内存吗?
- php - 使用 PHP 打开文件的首选 fopen 模式是什么?
- c# - 有没有办法在移动后停止将 pos2 移动到 pos1 ?
- python - 如何在 PyCharm 中快速对齐鼠标指针?
- php - 重命名库包含上的特定符号,以避免致命错误“无法重新声明”
' - tsql - SQL - 如何使用 DECLARE 语句在 SQL 查询中选择其他参数
- php - 自定义帖子类型查询在短代码中创建空白无限循环
- c++ - 尽管初始化,可变大小的对象可能未初始化错误
- powershell - 无法使用 Send-MailMessage 从不同目录发送多个附件