Export Geoprocessing Results to Text File?

5034
6
01-26-2012 09:00 AM
ChristinaGnadinger
New Contributor II
I am hoping that this is possible.

I am running cache processes (currently through Model Builder) that sometimes last past the time I leave for the day. At the same time, overnight (late) I have routines that run updates and close out my connections to GIS (if it is still open).

Occasionally my cache processes will have errors, i.e. the "Failed to Manage tiles.." errors. These show up on the GP window but for some reason do not write out to the GP log file.

Is there a way that we can capture the results in the geoprocessing window (using Model Builder or similar) and export them to a text file or is my best option to run these as python scripts? I'm trying to avoid the latter just because I want to follow the process initially but at the same time I have no way of knowing whether the caches 'really did' complete or not since those details do not get translated.

Any suggestions would be greatly appreciated!

Thank you for your help!
0 Kudos
6 Replies
GeorgeNewbury
Occasional Contributor
You can bring your Modelbuilder work into python, and then add some python code to write out a text file. For example you could have the python code comb through the cache files to report how many files have been written or when the last tile / compact cache file was created / updated.   Also Python can output text to the geoprocessing window just like modelbuilder. You can also create log files with Python which make it easier to create a single summary text file.


-George
0 Kudos
curtvprice
MVP Esteemed Contributor
I am hoping that this is possible.

I am running cache processes (currently through Model Builder) that sometimes last past the time I leave for the day. At the same time, overnight (late) I have routines that run updates and close out my connections to GIS (if it is still open).

Occasionally my cache processes will have errors, i.e. the "Failed to Manage tiles.." errors. These show up on the GP window but for some reason do not write out to the GP log file.


If you run the model as a model tool (ie. double click the model and click OK) and you have gp logging clicked on in the application options, everything should write to the the gp log file.

An approach that may be more appropriate for a job you often repeat is to run your model using a simple python script, such as:

# e:\work\runmodel.py
import arcpy
arcpy.CheckOutExtension("Spatial") # extension, if needed
arcpy.ImportToolbox(r"e:\work\mytoolbox.tbx") 
arcpy.MyModel_mytools() # "mytools" is your toolbox's alias
arcpy.AddMessage("Processing completed.")


Start your python script before you go home like this:

1. Open a command window: Windows -> Run... -> cmd.exe
2. In the command window, run your python script:  
cd /d e:\work
runmodel.py > runmodel.log  2<&1


The ">" sends script output to the log file, and the fancy foot work "2<&1" redirects any system errors to go into the log file instead of to the command window. (Good old DOS!)

You could also put the above DOS commands in a .bat file.
0 Kudos
AndrewChapkowski
Esri Regular Contributor
If you switch from model builder to python scripting, there is a module called 'logger' which will allow you to capture and write data to a file.
import logging

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(levelname)s %(message)s',
                    filename='/tmp/myapp.log',
                    filemode='w')
logging.debug('A debug message')
logging.info('Some information')
logging.warning('A shot across the bows')


See http://docs.python.org/release/2.6.4/library/logging.html for further details. 
Another good resource to look at is: http://blog.doughellmann.com/2007/05/pymotw-logging.html
0 Kudos
ChristinaGnadinger
New Contributor II
Thank you all for your advice and suggestions! I'm going to try and finalize this first thing today.

The advantage of running the caches through the model builder is that I can monitor the percentage completion but the disadvantage definitely occurs when I leave work and can't find out if the cache was truly successful. I will probably leave the models as a second option but will look into running them as python scripts outside of GIS.

Is there a way to write out percent milestones through python (as far as percent completed) or am I hoping for too much? 🙂

THANK YOU!!



Curtis,

I still use DOS all the time .. in some cases nothing beats it! 🙂 .. I have it tied to just about every nightly process that I can!
0 Kudos
TimothyHales
Esri Notable Contributor
I believe the information already provided is very good. Here is a KB Article that may be helpful as well:

HowTo: Write the results of geoprocessing tools to a text file using Python
0 Kudos
curtvprice
MVP Esteemed Contributor
Is there a way to write out percent milestones through python (as far as percent completed) or am I hoping for too much?


If the messages are only going into the progressor bar - that's not doable. But if your model building is looping all messages you see in the dialog will show up in the log. You can of course view the log as long as you don't edit it. (I have the GNU unix utilities so I can for example, look at the last few lines with the tail command.
0 Kudos