0

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.

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.

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?

2
  • alternative program to Task Scheduler or scripts? - schtasks
    – Stephan
    Commented Dec 20, 2017 at 16:45
  • 1
    Windows Task Scheduler just kicks off the process, so it is almost certainly not the issue here.
    – TylerH
    Commented Aug 28, 2023 at 18:15

3 Answers 3

1

As the above has no exit strategy and is delayed for at least 25 minutes, this batch file code may be better suited to your need, drop a reference into your login batch or other trigger...

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

if "%timeHrs%" geq 6 if "%timeHrs%" leq 9 (
    [command to trigger Python script]
    exit /b 0
)

timeout /t 1500
goto loop
1
  • Does this have to executed manually to initiate?
    – Steven
    Commented Jun 3, 2021 at 23:55
0

'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.

1
  • Does this have to executed manually to initiate?
    – Steven
    Commented Jun 3, 2021 at 23:55
0

Add /a flag to SET command to set value as integer. I was able to compare values in IF statement only then. Code to run task after 8:14 am:

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

if %timeHours_2% geq 8 if %timeMin% geq 14 (
  echo OOOwww
  [command to trigger Python script]
  exit /b 0

)
timeout /t 3
goto loop

Not the answer you're looking for? Browse other questions tagged or ask your own question.