[英]Running a python script through Windows Scheduler not working
I am trying to automate a python script through the Windows Task Scheduler but its not working.我正在尝试通过 Windows 任务计划程序自动化 python 脚本,但它不起作用。 At the end of my python script.
在我的 python 脚本结束时。 two CSV files should be created but they arent.
应该创建两个 CSV 文件,但它们不是。
I tried the following: 1. Copied the address of my python.exe to Program/Script.我尝试了以下方法: 1. 将我的 python.exe 的地址复制到 Program/Script。
C:\Program Files\Python35\python.exe
C:\Program Files\Python35\python.exe
Historical Aggregation.py
历史聚合.py
C:\Users\myname\PycharmProjects\Project1
C:\Users\myname\PycharmProjects\Project1
Am I missing something我错过了什么吗
To simplify, we can create a really short .bat
file, that will only receive the necessary command to run your python script. 为简化起见,我们可以创建一个非常短的
.bat
文件,该文件仅会收到运行python脚本所需的命令。
To do so, try this: 为此,请尝试以下操作:
Create a executePy.bat
file in the same folder than your Python file (C:\\Users\\myname\\PycharmProjects\\Project1), with content: 在与Python文件(C:\\ Users \\ myname \\ PycharmProjects \\ Project1)相同的文件夹中创建
executePy.bat
文件,其内容为:
@echo off
"C:\Program Files\Python35\python.exe" "Historical Aggregation.py"
Then, on your task scheduler, simply schedule a test with Program/Script: 然后,在您的任务计划程序上,只需使用程序/脚本计划测试:
"C:\Users\myname\PycharmProjects\Project1\executePy.bat"
Leave Add Arguments
and Start In
in blank. 将“
Add Arguments
和“ Start In
留为空白。 Now, your task should be ready to run. 现在,您的任务应该可以运行了。
Another approach would be to set fields as: 另一种方法是将字段设置为:
"C:\\Program Files\\Python35\\python.exe"
“ C:\\ Program Files \\ Python35 \\ python.exe”
"C:\\Users\\myname\\PycharmProjects\\Project1\\Historical Aggregation.py"
“ C:\\ Users \\ myname \\ PycharmProjects \\ Project1 \\ Historical Aggregation.py”
I had a very similar issue, and solved it in a different way. 我有一个非常相似的问题,并以不同的方式解决了。 Here my step by step guide:
这是我的逐步指南:
Transform the python script to an .exe, using in the DOS cmd prompt the command: 在DOS cmd提示符下使用以下命令将python脚本转换为.exe:
pyinstaller -- onefile [name of the file.py]
Place the CSV file that you want to update in the same folder as the .exe file created 将要更新的CSV文件与创建的.exe文件放在同一文件夹中
Create a basic task on Windows Scheduler, with the following properties: 在Windows Scheduler上创建具有以下属性的基本任务:
General - select 一般-选择
Triggers – select 触发器–选择
Actions 操作
Conditions - select 条件-选择
Settings – leave the default options 设置-保留默认选项
Save the task by inserting the password 通过插入密码来保存任务
Leave the task status on “Ready” 将任务状态保留为“就绪”
Good luck! 祝好运!
I have a problem with the task exiting.. It runs, but then it says "task is currently running".我的任务退出有问题。它运行,但随后显示“任务当前正在运行”。 It's a 1 second python script... should run and end.. I'm using this for code:
这是一个 1 秒的 python 脚本......应该运行并结束......我正在使用它的代码:
C:\temp\python\file.bat C:\temp\python\file.bat
and it's content is:它的内容是:
@echo off C:/Users/benjune/AppData/Local/Programs/Python/Python310-32/python.exe C:\temp\python\ben\file.py @echo off C:/Users/benjune/AppData/Local/Programs/Python/Python310-32/python.exe C:\temp\python\ben\file.py
It's scheduled to run every 5 minutes, and should finish really quickly.它计划每 5 分钟运行一次,并且应该很快完成。 Should I use an exit or something after that?
之后我应该使用出口还是其他什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.