Select to view content in your preferred language

python script not run as a SQL Server scheduled job

6872
10
12-12-2012 01:25 PM
RobertHu
Emerging Contributor
Posted my problem in another forum (GP), and no luck. Try here.

Python 2.7
ArcGIS 10.1 (sp1)
ArcSDE 10.1 (sp1)
SQL Server 2008 R2 Standard (sp2)
Windows Server 2008 R2 Standard (sp1)

Run a batch file, which calls a python script, as SQL Server scheduled job. If the python script includes "import arcpy" statement, the script will fail without leaving any error message. The script works fine without the "import arcpy" statement. Tried same thing as a system scheduled task, the results are same.

While running the batch file from command line, it works fine with or without the "import arcpy" statement.

Anyone ever experienced same thing, and have a clue?

Thanks in advanced!
0 Kudos
10 Replies
LeonScott
Deactivated User
I have found a way to work around this issue. It seems a little convoluted, but it does work. You will need to use Powershell and install an additional module to enables Powershell to run Task Scheduler.  I think running Task Scheduler is integrated at Windows 8, but I'm not running that.  Once you have that set up try the following steps

Link to module
http://powershell.codeplex.com/releases/view/54703


1)  Create a schedule task and enable it, though don't set it to run

2)  Create a powershell script that will run your schedule task.  Mine looks like this
Import-Module PowerScheduledTasks
Start-ScheduledTask -TaskName Powershell

3)  In your SQL job add a (Cmd Exec) step that will call powershell with your script
powershell "C:\workspace\RunScheduledTask.ps1"


Hope this helps!


Leon
0 Kudos