Python called from batch file --> geoprocessing logs

304
1
01-24-2013 05:24 AM
JoepLuijten
New Contributor
Hi all,

I am calling a number of Python scripts from a batch file like below (simplified)

[INDENT]SET PATH=%PATH%;D:\apps\Python27\ArcGIS10.1
SET PYSCRIPT="D:\Projects\MyTestScript.py"
python %PYSCRIPT%[/INDENT]

and would like to benefit from the geoprocessing logging capabilities so that all messages written by arcpy.AddMessage() in the python scripts can be viewed later on from the ArcCatalog Geoprocessing > Results window.

I have added the following statements in the beginning of my Python scripts
    arcpy.SetLogHistory(True)
    arcpy.gp.logHistory = True

but that doesn't seem to have any effect.
Is the only way to save the geocompressing logging if you execute the scripts actually from a tool within the ArcCatalog environment?

Thanks for any suggestions,
Joep
Tags (2)
0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor
I just create my own .log file and write lines where needed.

#oLoc is just a network path string variable where I want to save this
#strD1 and strD2 are just variables of dates set previously

logpath = oLoc + "\\" + strD1 + "_to_" + strD2 + ".log"
logfile = open(logpath, 'w')
logfile.write("Log begin: " + str(log_startdate) + "\n")

#here is an example of how I am writting errors to the log file
# see if spatial analyst extension is available for use
availability = gp.CheckExtension("Spatial")
if availability=="Available":
   gp.CheckOutExtension("Spatial")
else:
   logfile.write("ERROR: Spatial Analyst extension not available" + "\n")
   return


logfile.close()
0 Kudos