我想为我的Windows批处理脚本构建一个逻辑,使其每天只在7:00和23:00之间运行。
我添加了如下所示的逻辑
SET "Offertime=%time:~0,2%"
IF %Offertime% leq 23 set "RunOffer=True"
IF %Offertime% geq 07 set "RunOffer=True"
IF "%RunOffer%"=="True" (
CALL "C:\TCC_Touch_Point_Folder\bin\Windows\core\Rcap_Offer_Cal.bat"
)
exit
但是这不起作用,有人可以让我知道我要怎么做吗?或任何更好的方法来实现此解决方案?
答案 0 :(得分:2)
您的条件始终为true,因为“ Offertime”小于/等于23或大于/等于7。这将起作用:
SET hour=%time:~0,2%
SET shouldrun=True
IF %hour% geq 23 SET shouldrun=False
IF %hour% leq 6 SET shouldrun=False
IF "%shouldrun%"=="True" (
CALL "C:\TCC_Touch_Point_Folder\bin\Windows\core\Rcap_Offer_Cal.bat"
)
答案 1 :(得分:0)
如果要在特定时间运行bat文件,通常的方法是使用Windows Task Scheduler对其进行调度。
或
然后创建一个任务来设置运行时间。