Python脚本未在任务计划程序中运行 [英] Python script not running in task scheduler

查看:66
本文介绍了Python脚本未在任务计划程序中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个python脚本正在文件夹之间复制一堆文件.在我尝试使用任务计划程序使其定期运行之前,该脚本将按预期运行.我用几种不同的方式运行它,但它总是可以正常运行,但是当我创建一个计划任务时,它给我一个错误(它说找不到我确认存在的文件夹).我尝试创建一个批处理文件以通过任务计划程序启动python脚本,尽管我手动运行该批处理文件时它可以工作,但它不起作用.我也尝试过通过计划任务使用python脚本作为调度程序的自变量调用python,但是它不起作用.通过python手动运行也可以,双击python脚本即可.仅通过调度程序,我无法运行它.可以说这很令人沮丧.有什么想法吗?

So I have a python script that is copying a bunch of files between folders. This script runs exactly as intended until I try to use the task scheduler to get it to run at regular intervals. I have run it several different ways and it always runs fine, but when I create a scheduled task it gives me an error (it says it can't find a folder that I have confirmed exists). I've tried creating a batch file to launch the python script through the task scheduler and it doesn't work, even though it works when I run the batch file manually. I've also tried calling python through the scheduled task with the python script as an argument through the scheduler and it doesn't work. Running manually through python also works, double clicking the python script work. It's only through the scheduler that I can't get it to run. Suffice to say it is quite frustrating. Any ideas?

推荐答案

使用任务计划程序"创建任务时,请确保为所有内容提供完整的PATH,例如:

When creating the task using Task Scheduler, make sure you give full PATHs to everything, for example:

Program/script: C:\Python27\python.exe
Add arguments (optional): -u "C:\Users\MyUserName\Documents\MyScript.py"
Start in (optional): C:\Users\MyUserName\Documents

第二,您也可以从脚本中强制工作文件夹:

Secondly, you could also force the working folder from within your script:

import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))

这篇关于Python脚本未在任务计划程序中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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