批处理文件中的 Python 脚本不会在任务计划程序中运行 [英] Python script from batch file won't run in task scheduler

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

问题描述

大家好,我遇到了以下问题,

Hi folks so I got the following problem,

我在批处理文件中有以下代码: ..\python-2.7.10.amd64\python.exe ./bin/bla.py ./conf/config.conf > ./logs/output.txt

I have the following code in a batch file: ..\python-2.7.10.amd64\python.exe ./bin/bla.py ./conf/config.conf > ./logs/output.txt

通过双击批处理,这就像一个魅力.接下来我的计划是通过将它添加到 Windows 中的任务调度程序来自动调用该批处理.所以我把所有的相对路径都改成了绝对路径:

This works like a charme by double clicking the batch. Next my plan was to automate the call of this batch by adding it to the task scheduler in windows. So I changed all the relative paths to absolute paths:

D:\path\to\python-2.7.10.amd64\python.exe D:\path\to\bin\bla.py D:\path\to\conf\config.conf > D:\path\to\logs\output.txt

这也可以通过双击批处理文件来实现.

This also still works by double clicking the batch file.

所以我的下一步是将批处理添加到任务调度程序,但是当我从那里运行它时,我收到此错误消息:

So my next step was adding the batch to the task scheduler but when I run it from there I get this error message:

回溯(最近一次调用最后一次):文件D:\path\to\bin\bla.py",第 159 行,在 logging.config.fileConfig(logFile) 文件D:\path"中\to\python-2.7.10.amd64\lib\logging\confi eConfig formatters = _create_formatters(cp) File "D:\path\to\python-2.7.10.amd64\lib\logging\confi reate_formatters flist = cp.get("formatters", "keys") 文件D:\path\to\python-2.7.10.amd64\lib\ConfigParser.引发 NoSectionError(section) ConfigParser.NoSectionError: No section: 'formatters'

因此,由于某种原因,python 脚本无法通过我认为的绝对路径找到 conf 文件,但我不明白为什么.我也用任务调度程序中的相对路径尝试过它显然也不起作用.

So for some reason the python script can't find the conf file by the absolute path I think but I don't understand why. I also tried it with the relative paths in the task scheduler it obviously also doesn't work.

你们中有人知道为什么它直接从批处理中工作而不是从任务调度程序中工作吗?

Does anyone of you have a clue why it works straight from the batch but not from the task scheduler ?

推荐答案

感谢大家的帮助.它确实只是"我必须设置为bat文件位置的工作目录

Thank you guys for your help. It was indeed "just" the working directory I had to set to the location of the bat file

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

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