Select to view content in your preferred language

Python Script not executing as sheduled in a .bat file

3379
7
10-29-2019 10:24 PM
wwnde
by
Regular Contributor

I have a script that runs well and as scheduled on a pc. It cant however be executed when scheduled on the server. It starts of and indicates it is complete within 2 seconds

Looked at all options discussed in this forum. Not able to resolve issue though. Last I tried to use is  ESRI Support- Scheduling Tasks and cant seem to understand what the highlighted below is and where it needs to be put in the task scheduler.

Would highly appreciate help.

0 Kudos
7 Replies
CCWeedcontrol
Frequent Contributor

If you layers in are an sde database you might need to include the full path of the layer in your script.

From

Database Connections\Geodatabase_blah_blah.sde

To

C:\Users\blah\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\Geodatabase_blah_blah.sde\featuredataset\feature class.

0 Kudos
wwnde
by
Regular Contributor

This script downloads a feature service from ArcGIS online and saves it to

a local server. So not an SDE database.

0 Kudos
CCWeedcontrol
Frequent Contributor

I would check to make sure you have the full UNC path to the server.

\\\\server\\folder\\folder\\

And you might consider using, scheduler has to have the full server path. At least that is the case for me.

pyodbc.connect

import pyodbc

conn = pyodbc.connect('Driver={SQL Server};' 'Server=server_name;' 'Database=db_name;' 'Trusted_Connection=yes;')

MichaelVolz
Esteemed Contributor

Is this your first attempt at running a python script from a bat file?  If so, maybe you want to start with a simpler script than downloading a feature service from AGOL to a local server as there might be multiple issues with a more complex script.  Once you get the simple script to execute as expected, than add the more complex code.

Does you server have access to the internet?  Due to security issues at my org, internet access is no longer allowed by default for servers.  Not sure this applies to you, but something to check with your IT staff.

0 Kudos
wwnde
by
Regular Contributor

The server has internet connection. Multiple other python 2 scripts running well. Issue was new script runs on python 3, I changed to redirect the exe file to 3 and that is causing issues. 

0 Kudos
JoeBorgione
MVP Emeritus

Why not just run it as a python file not as a .bat file?

Optionally, you can execute the flavor of python .exe you want in the Program/script window, and call the .py file as an argument...

That should just about do it....
wwnde
by
Regular Contributor

Optionally, you can execute the flavor of python .exe you want in the Program/script window, and call the .py file as an argument...

Quoted suggestion seems to work. I ran the ESRI's given code below

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])

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

and it pointed me to the following exe file

When changed to:\python.exe, it all went fine. I too think, it was executing in cd and not in the background (within task scheduler when logged off the server) because I had input mapped directory paths  as opposed to the full directory paths.

0 Kudos