I have a simple Python script that runs correctly when I launch it in Jupyter Notebook or after I convert it to .exe, but doesn't work when I launch it via Windows Scheduler (I tried to launch both the .py file and the .exe). What am I missing?
Background:
I have a simple 3.7 Python script which I would like to run at regular intervals. I am testing the approach with a simple Python script before moving to a more complex script.
The script I have works well when I launch it in Jupyter, but it doesn't work when using Windows Scheduler. What I did was, I created a basic task in Windows scheduler, and set the following properties:
- general: run only when user is logged in;
- triggers: daily;
- action: I have tried several combinations of inputs. The latest combo I tried is to have in "program/script" C:\Pythondata\dist\test.exe and no optional argument;
- conditions and settings: I kept the default options.
When I click on RUN task in Windows Scheduler, a command-like, black background windows appears for a few seconds, then it disappears, but nothing happens and the output txt file doesn't get edited. I get no error messages, and when I check the "History" of the task, it says "Task completed" or "Task registration updated". Basically, there seems to be no error, and yet, nothing happens.
I'd like to solve the issue using Windows Scheduler but also I am open to suggestions on ways to run the scripts regularly. However, I am a very basic Python user and may not be able to do more complex things. My system is a Windows 10 Home, Python 3.7.
Simple Code I am using:
import datetime
now = datetime.datetime.now()
file = open("testfile.txt","w")
file.write("Hello Word" + str(now))
print("done")
Note: The script writes the datestamp in a text file in the same folder of the .ipynb file. I have also converted the file to an .exe using pyinstaller. in both cases the script works well. However, it doesn't work with Windows scheduler.