Select to view content in your preferred language

How to fire python with arguments as scheduled task

11581
3
Jump to solution
04-09-2018 05:36 AM
ThomasColson
MVP Frequent Contributor

I'm trying to get a PY Script to run as a scheduled task with no success. It's very important to point out that I can get this to run by executing from cmd prompt as myself, the domain service account that will run the task, and other python scripts (without arguments) run fine in task scheduler  when I'm logged off, so various permissions issues are not the problem here. 

I've tried Run with Highest Privileges on and off. Never works. I get no error messages other than either the task completes instantly (should take about 15 minutes to run), or completes in 30 seconds. As mentioned above, the script works in other execution scenarios and under various user accounts, so I don't see a need to write a bunch of logging that's going to log nothing, as, far as I can tell, the first line of the python isn't getting executed (there's nothing to log if nothing is run). The only difference here is the addition of arguments at the end of the call to the python script, which is somehow throwing a monkey wrench into already finicky and pouty Task Scheduler, not known for its error reporting and logging. 

I've tried:

  1. Program Script:
    C:\Python27\ArcGIS10.5\python.exe
    Add Arguments (optional):
    C:\PRODUCTION\SOME_FOLDER\syncSurvey.py SOME.sde SOME_NAME https://services1.arcgis.com/SOME_ORG/arcgis/rest/services/service_SOME_ITEM_ID/FeatureServer US/Eastern https://www.arcgis.com SOME_ACCOUNT SOME_PW
    
    
    Program Script:
    C:\Python27\ArcGIS10.5\python.exe
    Add Arguments (optional):
    "C:\PRODUCTION\SOME_FOLDER\syncSurvey.py SOME.sde SOME_NAME https://services1.arcgis.com/SOME_ORG/arcgis/rest/services/service_SOME_ITEM_ID/FeatureServer US/Eastern https://www.arcgis.com SOME_ACCOUNT SOME_PW"
    
    
    Program Script:
    C:\Python27\ArcGIS10.5\python.exe
    Add Arguments (optional):
    "C:\PRODUCTION\SOME_FOLDER\syncSurvey.py" SOME.sde SOME_NAME https://services1.arcgis.com/SOME_ORG/arcgis/rest/services/service_SOME_ITEM_ID/FeatureServer US/Eastern https://www.arcgis.com SOME_ACCOUNT SOME_PW
    
    
    Program Script:
    C:\Python27\ArcGIS10.5\python.exe
    Add Arguments (optional):
    C:\PRODUCTION\SOME_FOLDER\syncSurvey.py "SOME.sde SOME_NAME https://services1.arcgis.com/SOME_ORG/arcgis/rest/services/service_SOME_ITEM_ID/FeatureServer US/Eastern https://www.arcgis.com SOME_ACCOUNT SOME_PW"
    
    
    Program Script:
    "C:\Python27\ArcGIS10.5\python.exe"
    Add Arguments (optional):
    C:\PRODUCTION\SOME_FOLDER\syncSurvey.py SOME.sde SOME_NAME https://services1.arcgis.com/SOME_ORG/arcgis/rest/services/service_SOME_ITEM_ID/FeatureServer US/Eastern https://www.arcgis.com SOME_ACCOUNT SOME_PW
    
    
    The following two just result in the task firing, but logging nothing, and never stopping...
    ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍Program Script:
    C:\Windows\System32\cmd.exe
    Add Arguments (optional):
    C:\PRODUCTION\SOME_FOLDER\SURVEY.BAT
    
    where SURVEY.BAT is: C:\Python27\ArcGIS10.5\python.exe C:\PRODUCTION\SOME_FOLDER\syncSurvey.py SOME.sde SOME_NAME https://services1.arcgis.com/SOME_ORG/arcgis/rest/services/service_SOME_ITEM_ID/FeatureServer US/Eastern https://www.arcgis.com SOME_ACCOUNT SOME_PW
    
    ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍Program Script:
    C:\Windows\System32\cmd.exe
    Add Arguments (optional):
    "C:\PRODUCTION\SOME_FOLDER\SURVEY.BAT"
    
    where SURVEY.BAT is: C:\Python27\ArcGIS10.5\python.exe C:\PRODUCTION\SOME_FOLDER\syncSurvey.py SOME.sde SOME_NAME https://services1.arcgis.com/SOME_ORG/arcgis/rest/services/service_SOME_ITEM_ID/FeatureServer US/Eastern https://www.arcgis.com SOME_ACCOUNT SOME_PW
    
    ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In the above, if I double click on the BAT file, it fires up a CMD prompt and runs fine, same when I do that same under the domain service account assigned to run the task (right click on bat, run as different user), once again confirming permissions aren't the issue here. How can I tell it's not working you ask? Nothing getting downloaded to C:\Users\[user]\AppData\Local\Temp, which would happen if a replica was created, and no new records are added to GDB, the opposite of what happens when I call it from cmd prompt. 

0 Kudos
1 Solution

Accepted Solutions
KevinDunlop
Frequent Contributor

This what ours looks like in Task Scheduler and it works without issue.  

View solution in original post

3 Replies
KevinDunlop
Frequent Contributor

This what ours looks like in Task Scheduler and it works without issue.  

LeonS
by
Frequent Contributor

I would try double quotes around each of your parameters.  I found that helps when URLs or file paths are passed as arguments through task manager.

Leon

ThomasColson
MVP Frequent Contributor

Great thanks. Results are promising, I'll update after a few iterations of the schedule...

0 Kudos