python脚本无法在任务计划程序中完成

时间:2013-12-17 14:32:26

标签: python task scheduler

如果我手动运行模块,下面将有以下python脚本执行,但是当我尝试在Windows任务计划程序中安排它时,它没有完成。我有一个日志文件作为脚本的一部分导出,它打印到'开始时间',但没有进入'结束时间',似乎表明它已经卡在复制功能上。

任务计划程序设置:

1)运行用户是否登录

2)以最高权限运行

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()

0 个答案:

没有答案