Python Forum
Running Python script through Task Scheduler?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running Python script through Task Scheduler?
#1
Question 
Hello,

This is my first try at running a Python (3.12.0) script through Windows 10's Task Scheduler… and it didn't work (as pretty much expected).

It's a simple script that 1) fetches a web page from the Net, 2) parses it to find something, and 3) sends an email through my ISP's SMTP server. The script works when launched manually.

First, I simply fed it the full path to the script: No email.

Next, I right-clicked on it, told TS to use the following app to run the script… still no email.
Quote:C:\Users\joe\AppData\Local\Programs\Python\Python312\python.exe

Does someone know/have a guess at what's wrong?

Thank you.

[Image: Task-Scheduler-Python.png]
Reply
#2
Does your script work when you run it from a terminal, line from CMD or powershell?
Reply
#3
This is just your path to Python,that shall in Program/script
Quote:C:\Users\joe\AppData\Local\Programs\Python\Python312\python.exe
Then in argument Add argument(absolute path to your Python code)

When test just use simple code that do something visible.
# open_notpad.py
import subprocess

subprocess.Popen(['notepad.exe'])
Create a new task eg name it Open Notepad next>next and input only the two Paths(Python and open_notpad.py) .
Then can go in and edit the created task.
Under settings choose Daily and set the start date and time to some short time in future.
Click on Repeat task every and change manually to 1 minutes from the dropdown.
Then change the duration to Indefinitely.
Now if work every minute notepad start.
Then just delete this task,and do process for the other task.
Reply
#4
Thanks.

Yes, like I said, "The script works when launched manually."

After I followed the instructions above, I can see the screen flicker every minute (looks like a CMD window opens and closes real fast) but I don't see Notepad.

If there's an easier way to run a Python script on Windows once every day, I'm not wed with MS' Task Scheduler.

[Image: image.png]
Reply
#5
Quote:The script works when launched manually.

Recently, can't say when exactly, not long ago, there was a post about something working from the command line, but not in Idle.

deanhystad said, the problem was probably Idle, and the OP tried some other IDE and it worked! (I tried it in Idle and it worked for me.)

Maybe your Task Scheduler, whatever that is, is the source of the problem?
Reply
#6
Try running the script in cmd or powerscript when you are in a different folder. Try running as a different user.
Reply
#7
What a pain…

What about using PyInstaller to compile the whole thing into a single binary?
Reply
#8
(Mar-10-2024, 06:03 PM)Winfried Wrote: After I followed the instructions above, I can see the screen flicker every minute (looks like a CMD window opens and closes real fast) but I don't see Notepad.
Then it probably working.
Change to this and test again,now it will force cmd to stay open.
import subprocess

subprocess.Popen(['C:/Windows/System32/notepad.exe'])
input('Press enter to exit')
Quote:If there's an easier way to run a Python script on Windows once every day, I'm not wed with MS' Task Scheduler.
Python job scheduling for humans
# pip install schedule
import schedule
import time

def job():
    print("I'm working...")

schedule.every(.1).minutes.do(job) # Woking test 10 sec
# schedule.every().day.at("10:30").do(job)
while True:
    schedule.run_pending()
    time.sleep(1)
Reply
#9
I'll try that instead.

Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  No Internet connection when running a Python script basil_555 8 663 Mar-11-2024, 11:02 AM
Last Post: snippsat
  Help Running Python Script in Mac OS emojistickers 0 351 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  Trying to make a board with turtle, nothing happens when running script Quascia 3 683 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,282 Jun-29-2023, 11:57 AM
Last Post: gologica
  Python script running under windows over nssm.exe JaroslavZ 0 724 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Running script with subprocess in another directory paul18fr 1 3,814 Jan-20-2023, 02:33 PM
Last Post: paul18fr
  count certain task in task manager[solved] kucingkembar 2 1,131 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  Running script on multiple files Afrodizzyjack 1 2,521 May-14-2021, 10:49 PM
Last Post: Yoriz
  Schedule a task and render/ use the result of the task in any given time klllmmm 2 2,108 May-04-2021, 10:17 AM
Last Post: klllmmm
  Error when running script on startup in Linux NoahTheNerd 0 1,974 Mar-07-2021, 04:54 PM
Last Post: NoahTheNerd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020