I have composed an ArcPy script which is run via a windows scheduler.The same script is loaded into a script tool so a user can run the process manually. I've used: get parameters as text, with or's and not's, to hard-wire the standard variables, if they are not speicifed.
ReportFolder = arcpy.GetParameterAsText(0)
if ReportFolder == '#' or not ReportFolder:
ReportFolder = "C:\\Data\\GIS"
The process runs and during so writes to a text file log, for example:
txtFile.write("= For ArcGIS 10.3.1: Date: "+str(timed)),txtFile.write ('\n')
I'd like to record what method was used to execute the script; was it via the windows scheduler, or by the script tool, or by a python client like PyScripter.
Is anyone aware of some form of os environment thingy that can be called by ArcPy?
2 Answers 2
I suggest use parameter passing to the script while you call this script using task scheduler and grab this parameter using sys module- as below
try:
data = "= For ArcGIS 10.3.1: Date: "+str(timed)+ sys.argv[1]+'\n' #grab parameters passed
except:
data = "= For ArcGIS 10.3.1: Date: "+str(timed)+ "Arcgis tool used"+'\n' # else arcgis tool used to run
And passing parameters to script in task scheduler is easy just add space and pass string ( like "test") as below-
Along a different line of thinking:
import os
ComputerName =os.getenv('COMPUTERNAME')
txtFile.write("= Run By: "+str(ComputerName)),txtFile.write ('\n')
os
module. You would not need to call it from ArcPy, just to use it in a script that was also using thearcpy
module.