14

I have a script which I wish to run on a regular monthly basis without me needing to open and run the it. I have referred to every web page I can find on Windows Task Scheduler and followed their instructions. However, running the script from Task Scheduler will only open the script in Python and not run it.

In the Task Scheduler Run Window, I have tried entering both the path to the script alone and the path to the script with the path to my Python program. I've also tried entering the path to my Python program as the script with my script as an argument as suggested in this blog post. My script is hard-coded, so I don't think I need to add any arguments.

Am I missing something obvious?


I was experiencing issues because I was using the path to the Python program and not the Python command line. I.e., I was using "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\Pythonwin.exe" when I needed to be using "C:\Python27\ArcGIS10.1\python.exe".

9
  • In this post if you read the comments it looks like the OP was able to get it to run by using cmd as the program and the script as the argument. Mar 24, 2015 at 12:45
  • Thank you. I haven't seen this post yet. I'll look it over and see if the information in it works for me.
    – Olivia
    Mar 24, 2015 at 12:51
  • And to whoever asked, I think I have 32 Python on a 64 machine.
    – Olivia
    Mar 24, 2015 at 12:54
  • So I tried the suggestion in the post you suggested, but I still don't seem to be having any luck. I tried using cmd as the program with /c C:\Python27.exe G:\Script.py as my arguments, but it gives me two errors: One from Python for Win32 saying that it could not load my script and an error saying that there was an error processing command line args.
    – Olivia
    Mar 24, 2015 at 13:10
  • 1
    If you are using ArcGIS, your python.exe may be in a location like this: "C:\Python27\ArcGIS10.3\python.exe". Make sure to verify you have the path to the executable correct in your .bat file.
    – crmackey
    Mar 24, 2015 at 13:22

2 Answers 2

18

I use the following settings to "Start a program" in the task scheduler. I find it best to use the full path to the Python executable to be safe.

Program/script: Full path to Python.exe, C:\Python27\ArcGIS10.2\python.exe

Arguments: Name of script, script.py

Start in: Location of script.py, something like C:\path\to\script

Also, if you pass in arguments to your script, include those with the arguments section, separated by spaces, script.py arg1 arg2 argn

2
  • awesome. was stuck with this.
    – Morse
    Oct 21, 2018 at 3:27
  • Hi Chad, I have tried the same but whenever I run the Task in Scheduler nothing happens. My locations are: C:\ProgramData\Anaconda3\python.exe , code.py , C:\Users\me\Downloads
    – West
    Apr 1, 2021 at 9:28
5

I have always set up simple batch files like this:

start C:\Python27\ArcGIS10.3\python.exe \\some_server\some_script.py

You'll just want to make sure the full path to the executable and script match exactly. If the path has any spaces in in it, you'll need to wrap it in double quotes. (" ")

1
  • I think this is what I have now. Program/script: "Python.exe" "\\serverconection\script.py" Task Scheduler then asks me if I want to make the server connection into an argument, I decline, and then the task won't run. If I do use the server connection as an argument though, the script will open but not run.
    – Olivia
    Mar 24, 2015 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.