13

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".

  • 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. – landocalrissian Mar 24 '15 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 '15 at 12:51
  • And to whoever asked, I think I have 32 Python on a 64 machine. – Olivia Mar 24 '15 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 '15 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 '15 at 13:22
17

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

  • awesome. was stuck with this. – Prateek Oct 21 '18 at 3:27
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. (" ")

  • 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 '15 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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