简体   繁体   English

Task Scheduler启动的Python脚本无法编辑文件

[英]Python script started by Task Scheduler can't edit file

I made this python script: 我做了这个python脚本:

# -*- coding: utf-8 -*-
from datetime import datetime
date = datetime.now()

file = open('myfile.dat', 'a+')
file.write(str(date)+'\n')

It works fine. 工作正常。 But when I schedule it in the Task Scheduler on Windows Server 2008 the script runs, but it doesn't write to the file. 但是,当我在Windows Server 2008的“任务计划程序”中计划它时,脚本会运行,但不会写入文件。 Task Scheduler uses my account to run the script so I don't understand why the results are different. Task Scheduler使用我的帐户运行脚本,所以我不明白为什么结果不同。

Any idea what I'm missing? 知道我缺少什么吗?

Have you tried using an absolute path to the file? 您是否尝试过使用文件的绝对路径?

I think there is also an option in task scheduler to specify where the script should be run, have you set that to the location of the file you want to write to? 我认为任务计划程序中还有一个选项可以指定应在何处运行脚本,您是否已将其设置为要写入的文件的位置?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM