python脚本赢得';无法在任务计划程序中完成
我有下面的python脚本,如果我手动运行该模块,它将执行,但是当我尝试在Windows任务调度器中调度它时,它没有完成。我有一个日志文件作为脚本的一部分导出,它打印到“开始时间”,但没有打印到“结束时间”,这似乎表明它在复制功能上卡住了 任务计划程序设置: 1) 无论用户是否登录,都要运行 2) 以最高权限运行python脚本赢得';无法在任务计划程序中完成,python,task,scheduler,Python,Task,Scheduler,我有下面的python脚本,如果我手动运行该模块,它将执行,但是当我尝试在Windows任务调度器中调度它时,它没有完成。我有一个日志文件作为脚本的一部分导出,它打印到“开始时间”,但没有打印到“结束时间”,这似乎表明它在复制功能上卡住了 任务计划程序设置: 1) 无论用户是否登录,都要运行 2) 以最高权限运行 import os import sys import shutil import glob import datetime import time from time import
import os
import sys
import shutil
import glob
import datetime
import time
from time import localtime, strftime
# Directories
dir_src = "W:\\Engineer\\DO NOT USE - Entrance Information"
dir_dst = "C:\\data\\engineering\\EntranceInformation"
# Export print messages to text file
time_now = strftime("%Y-%m-%d_%H-%M-%S", localtime())
logfile = 'C:\\logs\\Engineer Entrances\\'+time_now+'.txt'
f = open(logfile, "w")
# Name of script
script = "CopyPasteEngineerEntrancePDF.py"
print >>f, "Script: ", script
# Get start time
start_time = datetime.datetime.now()
start_time_readable = strftime("%Y-%m-%d %H.%M.%S", localtime())
print >>f, "Start Time: ", start_time_readable
# Copy files
for file in os.listdir(dir_src):
print >>f, file
if file.endswith(".pdf"):
print >>f, file
src_file = os.path.join(dir_src, file)
dst_file = os.path.join(dir_dst, file)
shutil.copy(src_file, dst_file)
print >>f, "Source File: ", src_file
print >>f, "Destination File: ", dst_file
# Get end time
end_time = datetime.datetime.now()
end_time_readable = strftime("%Y-%m-%d %H:%M:%S", localtime())
print >>f, "End Time: ", end_time_readable
# Get elapsed time
elapsed_time = datetime.datetime.now() - start_time
print >>f, "Elapsed Time: ", elapsed_time
# Get count of files copied
file_count = len(glob.glob1(dir_dst,"*.pdf"))
print >>f, "Files Copied: ", file_count
# Close text file
f.close()
在
#Copy files
部分中加入更多的print
语句,以查看它的确切位置。还打印src_文件
和dst_文件
的值。添加了src_文件和dst_文件的打印语句。日志文件看起来正确,显示了正确的源文件和目标文件。手动运行时工作。已尝试任务计划程序…日志文件未显示源文件或目标文件。请继续添加调试语句。打印os.listdir
结果中每个文件的名称(即if file.endswith
部分之前),然后再次在PDF部分中打印。查看该if
语句中包含的文件。我使用的是python 2.7…任何模块的版本都有问题吗?