Interesting requirement

1852
4
Jump to solution
10-01-2013 10:50 AM
JamesCrandall
MVP Frequent Contributor
I have an interesting requirement and looking for comments...

In order to reduce duplication of modules/def's in our codebase, I need a way to determine WHERE something is being executed from.  That is, our requirement is users will have the ability to execute a process from an ArcToolbox OR from a command line (both with args/params).

Is there a way to detect/test if it is being executed from Command line or from an ArcToolbox?  The reason is that I will need to set variables in the script with the command line args or toolbox (GetParameter).

Thanks,
j
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III
0 Kudos
4 Replies
JamesCrandall
MVP Frequent Contributor
I think I can use sys.stdout to do this...

This code, executed from PythonWin prints "pwin.framework.interact.InteractiveView at..."


value = sys.stdout
print value



This code, executed from an ArcToolbox script with the .py as source prints "geoprocessing sys.stdout object object at..."


value = sys.stdout
arcpy.AddMessage(str(value))



Any other ideas are appreciated!
0 Kudos
JasonScheirer
Occasional Contributor III
0 Kudos
JamesCrandall
MVP Frequent Contributor
sys.executable.


That'll work too!

Thanks Jason.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Here's what I've come up with:


origapp = sys.executable
if "ArcMap" in origapp:
    arcpy.AddMessage("...The python script is being executed from ArcGIS/Toolbox")
elif "Pythonwin.exe" in origapp:
    print "...The python script is being executed from PythonWin"

0 Kudos