Select to view content in your preferred language

Scheduled task to call a batch file calling a python script - python not executing

869
3
12-29-2011 05:59 AM
MichaelBlom
Deactivated User
Hello,

I'm not sure the above is possible tbh.

The python calls within the batch file are just skipped over, no errors. 

The account calling the sched task has the necessary file/folder/sqlserver permissions, in fact, when I open a command line window and run the batch file from here (as the same user executing the sched task), everything works fine.

It's really just from within the sched task that things don't work.
Interestingly, if I make the user sysadmin, the sched task can then perform the python sections.

It's a 64 bit windows server 2008 R2 box, arcgis 10 sp3, python 2.6

What we think it really comes down to (when running under a scheduled task) how the Python script is talking to ArcGIS system (potentially around licensing ? lot of references to FlexLM missing when analyzing a trace where it fails).

This is really puzzling me. Help please!

Mike
Tags (2)
0 Kudos
3 Replies
ChristinaGnadinger
Emerging Contributor
I have quite a few scheduled tasks which start a batch file and then start a python script from there. You may have a quirk that the python script encounters which causes it to bail immediately.

Sometimes what helps is to add a line (in the batch file itself) that will write the processing output to a text file.

Something like...


PythonScript.py >  C:\Log\LogFile.txt 2>&1


I also have the Python script itself write out a log file in case there are any errors I can't see in the command line log file.


Something like ...

import arcpy, os

outtable = open(r"C:\Log\PythonLog.txt", "w")

... 

((((variables here))))

try: 

((((indented code here)))) 


    outtable.write("Some sort of text string here to let you it worked")
except arcpy.ExecuteError:
    outtable.write(arcpy.GetMessages())

outtable.close()



If the Python script succeeds you'll get that 'success text.' If not it may give you an idea on what the error is. Depending on if and when an error occurs makes the difference on which file you will find it in.

Hope this helps!


Hello,

I'm not sure the above is possible tbh.

The python calls within the batch file are just skipped over, no errors. 

The account calling the sched task has the necessary file/folder/sqlserver permissions, in fact, when I open a command line window and run the batch file from here (as the same user executing the sched task), everything works fine.

It's really just from within the sched task that things don't work.
Interestingly, if I make the user sysadmin, the sched task can then perform the python sections.

It's a 64 bit windows server 2008 R2 box, arcgis 10 sp3, python 2.6

What we think it really comes down to (when running under a scheduled task) how the Python script is talking to ArcGIS system (potentially around licensing ? lot of references to FlexLM missing when analyzing a trace where it fails).

This is really puzzling me. Help please!

Mike
0 Kudos
MichaelBlom
Deactivated User
Thanks for taking the time to respond Christina.

I had set up all my statements to append into a log file (>>), and have also implemented the same in the python, unfortunately, the python script is never entered.

The python script also doesn't fail, it just gets skipped over.

I have decided to just allow the account that runs the scheduled task to be an administrator on the box. 

Again, the crazy thing is that if I runas this account from a cmd window, everything's smooth, it's only via scheduled task.  My colleague suggested filling in the "start in this directory" text box, but I've already set that to be the path to my original .bat file.

Stumped.
0 Kudos
HemingZhu
Frequent Contributor
I have quite a few scheduled tasks which start a batch file and then start a python script from there. You may have a quirk that the python script encounters which causes it to bail immediately.

Sometimes what helps is to add a line (in the batch file itself) that will write the processing output to a text file.

Something like...


PythonScript.py >  C:\Log\LogFile.txt 2>&1


I also have the Python script itself write out a log file in case there are any errors I can't see in the command line log file.


Something like ...

import arcpy, os

outtable = open(r"C:\Log\PythonLog.txt", "w")

... 

((((variables here))))

try: 

((((indented code here)))) 


    outtable.write("Some sort of text string here to let you it worked")
except arcpy.ExecuteError:
    outtable.write(arcpy.GetMessages())

outtable.close()



If the Python script succeeds you'll get that 'success text.' If not it may give you an idea on what the error is. Depending on if and when an error occurs makes the difference on which file you will find it in.

Hope this helps!


Did you specify the path of python.exe in your batch file?
0 Kudos