Task scheduler shows python script shows as running but not working

Question:

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:UsersnAppDataLocalProgramsPythonPython310Libvenvscriptsntpython.exe" "C:UsersnDesktopdatashared_links.py" pause

Asked By: 01nowicj

||

Answers:

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\AppDataLocalProgramsPythonPython310python.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.

Answered By: 01nowicj

I had a similar issue with my python path. Be sure to check that your Task Scheduler python.exe path is the same as the interpreter path in your python compiler (PyCharm is mine). If they don’t match, it won’t run. After changing mine to the correct path it worked as expected.

Answered By: Caleb C