问题描述
不确定是否有人遇到过这种情况,但我会采纳有关故障排除和/或替代方法的建议.
Not sure if anyone has run into this, but I'll take suggestions for troubleshooting and/or alternative methods.
我有一台运行多个计划任务的 Windows 2008 服务器.其中一项任务是使用 pscp 登录 linux box 的 python 脚本,检查新文件,如果有新文件,则将它们复制到 C: 驱动器上的本地目录.我也在关键点将一些日志记录到脚本中,并且我正在使用 logging.basicConfig(level=DEBUG)
.
I have a Windows 2008 server on which I am running several scheduled tasks. One of those tasks is a python script that uses pscp to log into a linux box, checks for new files and if there is anything new, copies them down to a local directory on the C: drive. I've put some logging into the script at key points as well and I'm using logging.basicConfig(level=DEBUG)
.
我使用变量构建命令,command = 'pscp -pw xxxx name@ip:/c:\local_dir'
然后我使用 subprocess.call(command)
代码>执行命令.
I built the command using a variable, command = 'pscp -pw xxxx name@ip:/ c:\local_dir'
and then I use subprocess.call(command)
to execute the command.
现在是奇怪的部分.如果我从命令行手动运行脚本,它工作正常.下载并处理新文件.但是,如果任务计划程序运行该脚本,则不会下载新文件.该脚本在同一用户下运行,但产生不同的结果.
Now here's the weird part. If I run the script manually from the command line, it works fine. New files are downloaded and processed. However, if the Task Scheduler runs the script, no new files are downloaded. The script is running under the same user, but yet yields different results.
根据脚本在linux box上创建的日志文件,脚本成功登录linux box.但是,尽管有新文件,但不会下载任何文件.同样,当我通过命令行运行它时,会下载文件.
According to the log files created by the script and on the linux box, the script successfully logs into the linux box. However, no files are downloaded despite there being new files. Again, when I run it via the command line, files are downloaded.
有什么想法吗?建议,替代方法?
Any ideas? suggestions, alternative methods?
谢谢.
推荐答案
我在 Linux VM 上尝试打开 MS Access 数据库时遇到了同样的问题.在 Windows 7 命令提示符下运行脚本有效,但在任务计划程序中运行它没有.使用任务计划程序,它会找到数据库并验证它是否存在,但不会返回其中的表.
I had the same issue when trying to open an MS Access database on a Linux VM. Running the script at the Windows 7 command prompt worked but running it in Task Scheduler didn't. With Task Scheduler it would find the database and verify it existed but wouldn't return the tables within it.
解决方案是让 Task Scheduler 作为程序/脚本运行 cmd,参数为 /c python C:\path\to\script.py(在 Add参数(可选)).
The solution was to have Task Scheduler run cmd as the Program/Script with the arguments /c python C:\path\to\script.py (under Add arguments (optional)).
我不能告诉你为什么这有效,但它解决了我的问题.
I can't tell you why this works but it solved my problem.
这篇关于通过执行 pscp 的 Windows 任务调度程序运行 python 脚本的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!