如何不使用Windows Task Scheduler计划运行bat文件? [英] How to schedule running a bat file not using Windows Task Scheduler?

查看:372
本文介绍了如何不使用Windows Task Scheduler计划运行bat文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个触发Python脚本的批处理(* .bat)文件,该脚本大约需要25分钟才能交互完成(手动通过命令提示符).该批处理文件需要每天早上运行.

I have a batch (*.bat) file that triggers a Python script and this script takes about 25 minutes to complete interactivly (through command prompt manuallly). This batch file needs to run in the morning on a daily basis.

当我尝试在Windows Task Scheduler上将其设置为Scheduled Task并在该位置运行时,它花费的时间几乎比交互式花费的时间多一倍.即使我在xml中将优先级"设置从默认的7设置为4(更高的优先级),也没有任何区别.更改优先级设置仅适用于I/O优先级,而不适用于内存优先级",该优先级仍保持为4(交互式运行向下1级,即5).内存优先级在支持长期过程中起着重要作用.

When I tried to set it as a Scheduled Task on Windows Task Scheduler and ran it there, it took nearly double the time than it did interactively. Even if I set the Priority settings from the default 7 to 4 (higher priority) in the xml, it didn't make any differnce. Changing the Priority settings only works for I/O Priority but does not work for Memory Priority, which still remains at 4 (1 level down the interactive run which is 5). Memory Priority plays an important role in supporting a long process.

我想知道是否有一种方法可以将bat文件作为计划任务触发,而不使用Task Scheduler,Task Scheduler的替代程序或脚本?

I am wondering if there is a way to trigger the bat file as a scheduled task but not using Task Scheduler, alternative program to Task Scheduler or scripts?

推荐答案

超时"可能是在没有任务计划程序的情况下计划任务的好命令.

'Timeout' might a good command to schedule your task without Task Scheduler.

timeout /t 1500
[command to trigger Python script]

因此,您想要此批处理文件需要在早上运行...",您还可以设置开始时间和结束时间:

So you want 'This batch file needs to run in the morning...', you can set the start time and end time as well:

set timeHrs=%time:~0,2%
set timeMin=%time:~3,2%
set timeSec=%time:~6,2%

[insert timeout command]

if "%timeHrs%" geq 6 if "%timeHrs%" leq 9 [command to trigger Python script]
rem The above command is check if Hour is in 6-9 (in morning).

如果需要,您可以在下面复制代码(您可能还需要编辑代码):

If you want then you can copy code below (you might have to edit code as well):

@echo off
:loop
set timeHrs=%time:~0,2%
set timeMin=%time:~3,2%
set timeSec=%time:~6,2%

timeout /t 1500

if "%timeHrs%" geq 6 if "%timeHrs%" leq 9 [command to trigger Python script]
goto loop

您还希望在代码中添加出口,但我认为您不需要它,只需让代码每天运行即可.

You also want to add the exit in code as well, but I think you don't need it, just let the code run everyday.

这篇关于如何不使用Windows Task Scheduler计划运行bat文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆