Reputation: 1271
I currently have a Python script that scrapes some data from the internet, then saves it as a pickle
file. When running this from a terminal with python filename.py
it saves correctly, since the Date Modified
field of the pickle
file changes. However, when running with the built-in scheduler it doesn't actually save the pickle
file, since the Date Modified
isn't changed, despite seeing the Python script being executed (terminal opens up and I see the script running).
I ticked the Run with highest privileges
box in the scheduler, and despite that it doesn't save the pickle
file. I thought it had to do with it not having write permission, but if it has the highest priviliges, surely it can save a file?
At the scheduled time a terminal opens, so I know it is actually being executed (print a message to make sure), but it doesn't show an error about the fact that it couldn't save the file or anything like that. The only reason I know it's not working is the Date Modified
field not changing. How can I fix this?
Upvotes: 0
Views: 1056
Reputation: 13185
Windows Task Scheduler has a default working directory of C:\Windows\System32
. If you set a relative path to the file you are trying to write, it will likely be written into that directory. If you open a Command Prompt in the directory of your script and run it, the relative path will be that directory. So, you actually have two copies of the pickle file.
If you set an absolute path in your script to the file you want to write to, both methods of running your script will write to the same file.
Upvotes: 2