gpt4 book ai didi

windows - 使用 PowerShell 每 x 秒运行一次批处理文件

转载 作者:可可西里 更新时间:2023-11-01 13:04:20 26 4
gpt4 key购买 nike

我想使用 Windows PowerShell 脚本每 x 秒运行一次批处理文件。所以这是一遍又一遍地运行同一个批处理文件。

我已经做了一些查找,但找不到我要找的东西。它适用于我想在 Windows XP 机器上运行的东西。我以前曾多次使用 Windows Scheduler 来做类似的事情,但由于某种原因,Windows Scheduler 只运行一次……然后就没有了。我也不想让批处理文件自己调用,因为它运行这么多次后会出错。

最佳答案

只需将对批处理文件的调用放在一个 while 循环中,例如:

$period = [timespan]::FromSeconds(45)
$lastRunTime = [DateTime]::MinValue
while (1)
{
# If the next period isn't here yet, sleep so we don't consume CPU
while ((Get-Date) - $lastRunTime -lt $period) {
Start-Sleep -Milliseconds 500
}
$lastRunTime = Get-Date
# Call your batch file here
}

关于windows - 使用 PowerShell 每 x 秒运行一次批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2426993/

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