Is anyone able to run a script through Windows Task scheduler using ArcGIS Pro? As a test I have an extremely simple script (just copying a feature) that runs fine within ArcGIS Pro.
import arcpy
arcpy.management.CopyFeatures("C:\CityScripts\ScheduledTasks\SafewatchCameras\Data\General.gdb\SafewatchCameras", "C:\CityScripts\ScheduledTasks\SafewatchCameras\Data\General.gdb\SafewatchCamerastemp2", None, None, None, None)
I setup the Task Scheduler as recommended by the ArcGIS Pro help and while the Task completes successfully nothing happens with the script.
Put in a call to ESRI tech support but they said it was a Windows issue and therefore couldn't work on it.
Scott
Is this script being run on a desktop machine or a Windows Server? What is the operating system?
Michael,
Windows Server 2012 Standard.
To put it kindly, that response from Esri Support is rubbish (I had some other word choices but wasn't sure if the upcoming profanity filter would block them!).
I notice you are using non-escaped file paths. It is best to use either escaped paths or raw strings to prevent Python from misinterpreting any backslashes in your strings. Does your script file run properly if you run it outside of a scheduled task?
Have you tried running a Python script with no ArcPy calls but calling it the same (using C:\...\propy)?
Joshua,
Yeah I agree, I was pretty disappointed. If we were three hours into the call and getting nowhere that would be one thing. Or at least maybe point me somewhere in the right direction.
I notice you are using non-escaped file paths. It is best to use either escaped paths or raw strings to prevent Python from misinterpreting any backslashes in your strings. You lost me here. I know enough Python to be dangerous but not sure what this means.
Does your script file run properly if you run it outside of a scheduled task? Had trouble testing this. I've been using PyScripter on this machine to run our other scripts (which are all ArcGIS 10.3, 2.x versions) and I don't understand how to test using the Python install that comes with Pro.
It means you have to rewrite your script to be:
import arcpy
arcpy.management.CopyFeatures(r"C:\CityScripts\ScheduledTasks\SafewatchCameras\Data\General.gdb\SafewatchCameras", r"C:\CityScripts\ScheduledTasks\SafewatchCameras\Data\General.gdb\SafewatchCamerastemp2", None, None, None, None)
Notice I added an r in front of both your file paths. That makes it a raw string so that Python does not interpret the slashes as escape characters.
The set up I recommended was taken from the Esri website that explains how to Run Standalone Scripts. It works for running scripts on my local machine.
Oh, that's what those are
You should be using propy.bat, not just propy. This works for me:
Program/script:
"c:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat"
Add arguments (optional):
"C:\Users\Owner\Documents\Test.py"
I also agree that you should be using a raw string for the path and file name arguments in Python.
Richard,
It throws an error when I run it like this.
Not to ask the obvious, but you do have Pro configured for either offline use or to automatically sign in? And, has the profile/user/service that is running the scheduled task ever logged into Pro before?