计划的任务未在Windows中触发

发布于 2025-01-22 05:55:57 字数 2982 浏览 1 评论 0原文

我想每天5分钟每5分钟运行以下Python脚本:

c:\ users \ ****** \ desktop \ task \ task.py.py

i创建以下任务:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2022-04-18T16:12:35.5603012</Date>
    <Author>DESKTOP-*****\*****</Author>
    <URI>\tast test</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Repetition>
        <Interval>PT5M</Interval>
        <StopAtDurationEnd>false</StopAtDurationEnd>
      </Repetition>
      <StartBoundary>2022-04-18T00:00:00</StartBoundary>
      <EndBoundary>2023-04-20T16:06:26</EndBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>******</UserId>
      <LogonType>S4U</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <DeleteExpiredTaskAfter>P30D</DeleteExpiredTaskAfter>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT1M</Interval>
      <Count>3</Count>
    </RestartOnFailure>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Users\*****\AppData\Local\Programs\Python\Python39\python.exe</Command>
      <Arguments>task.py</Arguments>
      <WorkingDirectory>C:\Users\****\Desktop\task</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

python脚本不会每5分钟执行一次,但是下一个运行时会更改,最后一个运行时间仍然显示为< a href =“ https://i.sstatic.net/tyl1f.png” rel =“ nofollow noreferrer”>

I would like to run the below python script every 5 mins on the daily basis:

C:\Users\******\Desktop\task\task.py

I created the below task:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2022-04-18T16:12:35.5603012</Date>
    <Author>DESKTOP-*****\*****</Author>
    <URI>\tast test</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Repetition>
        <Interval>PT5M</Interval>
        <StopAtDurationEnd>false</StopAtDurationEnd>
      </Repetition>
      <StartBoundary>2022-04-18T00:00:00</StartBoundary>
      <EndBoundary>2023-04-20T16:06:26</EndBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>******</UserId>
      <LogonType>S4U</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <DeleteExpiredTaskAfter>P30D</DeleteExpiredTaskAfter>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT1M</Interval>
      <Count>3</Count>
    </RestartOnFailure>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Users\*****\AppData\Local\Programs\Python\Python39\python.exe</Command>
      <Arguments>task.py</Arguments>
      <WorkingDirectory>C:\Users\****\Desktop\task</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

The python script is not executed every 5 mins, but the Next runtime gets changed and the last run time still shows as enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吲‖鸣 2025-01-29 05:55:57

如@daemon的注释中所述,在设置计划的任务操作时,命令字段应包含可执行的路径(例如c:\ users \ ******* \ appdata \ appdata \ local \ local \ program \ python \ python39 \ python.exe),参数字段应包含要运行的文件的完整路径,在这种情况下,这可能是c:\ users \ users \ **** \ desktop \ desktop \任务\ task.py

所以我希望动作部分看起来像

<Actions Context="Author">
  <Exec>
    <Command>C:\Users\*****\Python39\python.exe</Command>
    <Arguments>C:\Users\****\Desktop\task\task.py</Arguments>
  </Exec>
</Actions>

As stated in the comment from @Daemon, when setting up a scheduled task action, the command field should contain the path to the executable (e.g C:\Users\*****\AppData\Local\Programs\Python\Python39\python.exe) and the arguments field should contain the full path to the file you want to run, which in this case should presumably be C:\Users\****\Desktop\task\task.py.

So I would expect the action section to look like

<Actions Context="Author">
  <Exec>
    <Command>C:\Users\*****\Python39\python.exe</Command>
    <Arguments>C:\Users\****\Desktop\task\task.py</Arguments>
  </Exec>
</Actions>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文