How to schedule running a bat file not using Windows Task Scheduler?

后端 未结 2 1033
北海茫月
北海茫月 2021-01-26 07:27

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 nee

相关标签:
2条回答
  • 2021-01-26 07:56

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

    0 讨论(0)
  • 2021-01-26 08:00

    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
    
    0 讨论(0)
提交回复
热议问题