Running a Python Script as a Windows Task

Posted on Posted in Uncategorized

Running the Python Script as a Windows Task

You will probably to want the preceding script to fire off at an interval, possibly on a Windows machine. Here's my method for setting up Python scripts to run as tasks on Windows systems. You will first want to set up a basic task in the Windows Task Scheduler.


You will need only one trigger for daily. Note that if you're using a task that you want to run slightly more often you will want to use the "repeating" option near the bottom, with a duration of "Infinity". For monitoring scripts I usually prefer to have them start to check something and then stop rather than running continually since this eliminates the chance that they might silently crash or fail to start at boot.


For actions you'll want just one to run the application, something like the following.

powershell -command &{python <absolutepath>.py}

With powershell as the application and everything beyond that as the command passed to it. If you specify the operating directory you won't need an absolute path (which includes the drive letter), and this might help if your application uses relative pathing for the rest of its files.