Python script as sheduled task (ArcGIS Pro)

13685
31
09-14-2018 06:34 AM
City_of_Greenville__SCGIS
New Contributor III

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

31 Replies
RichardFairhurst
MVP Honored Contributor

I just upgraded from Windows 7 to Windows 10 and found that the path I got from the  Run Standalone Scriptshelp page that ran propy.bat in Task Scheduler under Windows 7 does not work under Windows 10.

"c:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat" works for me in Windows 7, but not in Windows 10.

c:\Progra~1\ArcGIS\Pro\bin\Python\scripts\propy.bat works for both Windows 7 and Windows 10.

So Scott from City of Greenville was correct that the path from the help page didn't work, at least under Windows 10.

MichaelVolz
Esteemed Contributor

I think the OP was trying to run python scripts on Windows Server.

The following thread shows a solution for Pro, but it does require having the ability to upgrade to Windows Server 2016.

https://community.esri.com/message/696252-python-351-script-wont-run-via-windows-task-scheduler-when... 

0 Kudos
AndrewL
Occasional Contributor II

We just migrated to a Windows 2019 server and c:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat kept failing immediately. I tried your suggestion of c:\Progra~1\ and it worked. Thanks!

0 Kudos
MichaelVolz
Esteemed Contributor

How about calling python.exe from it's installed location?  For me it would be:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe would be the Program/script

and the py file would be the Add arguments.

Is the task configured to "Run with highest privileges"?

0 Kudos
City_of_Greenville__SCGIS
New Contributor III

Same error.

This is how we (successfully) run all of our ArcMap based python scripts though.

0 Kudos
MichaelVolz
Esteemed Contributor

Here is another threads related to this issue:

Python 3.x Scheduled Task Fails 

It provides insight on the problem, but I'm not sure it has been resolved.

City_of_Greenville__SCGIS
New Contributor III

Yeah this is definitely related.  When I select "Run only when user is logged on" it'll run.  I wonder if it's OS as your first question alluded to?  It seemed in that thread that people who were running Windows 2016 didn't have an issue. 

Also, separately, what a rabbit hole.  How is this not something that Tech Support doesn't want to jump into and solve and/or direct people to the appropriate resources?

MichaelVolz
Esteemed Contributor

Do you have Windows Server 2012 or Windows Server 2012 R2? 

0 Kudos
ThomasColson
MVP Frequent Contributor

The big question is, does the script run when using the account that will run it in task scheduler (right click run as)? Ever since I moved all my task scheduler stuff to Pro, nothing but a nightmare of scripts randomly failing, etc. I currently have one bug open related to pro py running as a scheduled task. Same scripts have worked fine in Arcmap for years. So it's not a windows issue. Also, has your IT person set this task up for you? There are a lot of permissions flaming hoops you have to jump through to get a scheduled task to run, and most users login does not allow it to run if you're logged off. 

City_of_Greenville__SCGIS
New Contributor III

It does appear to be an operating system issue as I ran it on another serving that's running Windows 2016 and it was successful.  Seemingly everything else was the same (admin rights, etc.)  I sent a message to our IT dept for some clarity as I'm not sure if there might be something specific to us or if it's specific to Windows 2012.