1

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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 3, 2016 at 2:28
1
  • 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. Commented Feb 3, 2016 at 2:44

2 Answers 2

3

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-

demo

answered Feb 3, 2016 at 7:30
0

Along a different line of thinking:

import os
ComputerName =os.getenv('COMPUTERNAME')
txtFile.write("= Run By: "+str(ComputerName)),txtFile.write ('\n')
answered Feb 3, 2016 at 7:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.