Dependencies
OS : Windows 10 Pro (64 bit)
IDE : Spyder 3 (Anaconda 3) with Python 3.9.7
Absolute path to python exe : C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe
Absolute path to python script : C:\Users\user\.spyder-py3\AutoScript\test.py
My python script
# -*- coding: utf-8 -*-
import datetime
with open('C:/Users/user/.spyder-py3/AutoScript/readme.txt', 'a+') as f:
f.write(f'{datetime.datetime.now()}\n')
The script simply writes the current time to a text file. If text file does not exist, it creates the text file.
If I run the script normally in my IDE, readme.txt
gets created with no errors and the file content is as expected.
Creating task with Task Scheduler
(click on the images to view them in high resolution)
Result
When I run the task on Task Scheduler and then refresh Task Scheduler, the "Last Run Result" of my task is (0x2331)
which seems to be a windows path issue
What I tried
Program/script | Add arguments : | Start in : | Last Run Result |
---|---|---|---|
C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe | C:\Users\user.spyder-py3\AutoScript\test.py | (0x2331) | |
"C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe" | "C:\Users\user.spyder-py3\AutoScript\test.py" | (0x2331) | |
C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe | test.py | C:\Users\user.spyder-py3\AutoScript\ | (0x2331) |
C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe | "test.py" | C:\Users\user.spyder-py3\AutoScript\ | (0x2331) |
"C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe" | "test.py" | "C:\Users\user.spyder-py3\AutoScript" | The directory name is invalid (x8007010B) |
"C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe" | "test.py" | C:\Users\user.spyder-py3\AutoScript\ | (0x2331) |
using batch file
Reference
executePy.bat
is in the same folder as test.py
executePy.bat
@echo off
"C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe" "test.py"
Program/script | Add arguments : | Start in : | Last Run Result |
---|---|---|---|
C:\Users\user.spyder-py3\AutoScript\executePy.bat | (0x2331) |
None of the above changes solved my issue. Any help is appreciated. Thanks.