我想使用
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
}