I've been trying to run a lengthy Python script in the task scheduler in order to be able to run it for a long periods of time. I've tried using bat files, inserting just the path to the actual python file, python.exe files, etc., but nothing seems to be working. I also have a path to another file in my script, I changed that to a full file path but nothing happens.
The script, when I run it in cmd or VS code connects to an API and adds specified elements to a SQL Server, however when I run it from the Task Scheduler, the database remains empty and nothing is added despite the fact that it is 'running'.
This is my current .bat file: "C:\Users\n\AppData\Local\Programs\Python\Python310\Lib\venv\scripts\nt\python.exe" "C:\Users\n\Desktop\data\shared_links.py" pause
Eventually I got it to work.
What I changed in the end that worked was changing the path to the pyton.exe
file to C:\Users\\AppData\Local\Programs\Python\Python310\python.exe
, as my previous one was a virtual environment path. I also added @echo off
in the beginning and deleted pause at the end of my .bat
file.