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?

  • 1
    I think Stack Overflow may be a better place to look for help on Python's os module. You would not need to call it from ArcPy, just to use it in a script that was also using the arcpy module. – PolyGeo Feb 3 '16 at 2:44

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

    data = "=    For ArcGIS 10.3.1: Date: "+str(timed)+ sys.argv[1]+'\n'  #grab parameters passed
    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')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.