Creating the exe should be the best method. But if you want to run it with the task scheduler you can do it in this way:
- Launch Window’s Task Scheduler
- Look for the The Actions pane(on the right) it has the Create Basic Task action. Click on it.
- This will open a wizard where you will define the name of your task, the trigger (when it runs), and the action (what program to run).
Action tab is where you specify the name of your Python script to run as well as any arguments to the script.
To ensure that your Python script will run regardless of the login account that the schedule task uses, and to avoid any confusion about which version of Python is used in mixed environments (64bit or 32bit), it is recommended that you run the Python executable with the name of your Python file as an argument to the executable.
Suppose the script you want to run is E:My script.py. Instead of running the script directly, instruct the task scheduler to run python.exe with the script as an argument. For example:
C:Python27ArcGIS10.2python.exe "E:My script.py"
The location of python.exe depends on your install. If you don’t know where it is, you can discover its location; copy and paste the following code into a new Python script then execute the script. The script will print the location of python.exe as well as other information about your Python environment.
import sys
import platform
import imp
print("Python EXE : " + sys.executable)
print("Architecture : " + platform.architecture()[0])
print("Path to arcpy : " + imp.find_module("arcpy")[1])
raw_input("
Press ENTER to quit")
After determining the location of python.exe, this is what is entered in the Action panel of the task scheduler:
If there are additional arguments (parameters) to your script, provide them after the path to your script. Hope this helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…