I feel like I'm missing a very basic concept when it comes to publishing python toolbox scripts to a geoprocessing server. I've scoured the ArcGIS online help (not saying I've read everything, and it's possible I missed the important part of information in all that I've read), but I think my issue is understanding path specifications, especially when it comes to the server. I'll try to explain as best I can:

I have a python toolbox script that takes a .tif file representing elevation, and a .cfg file that supplies configuration input to a custom command line interface (CLI) executable.

The "getParameterInfo()" block of code is as follows:

paramElevation = arcpy.Parameter(displayName="Elevation File (.tif, .asc, .img)",

paramConfig = arcpy.Parameter(displayName="WindNinja Configuration File",

paramOutFile = arcpy.Parameter(displayName="Output File",
                                     direction = "Output")

In the "execute()" block of code we have:

ninjaPath = "C:/WindNinja/WindNinja-2.3.0/bin/WindNinja_cli.exe" #Location of windninja CLI on server

imgFile = parameters[0].valueAsText #User specified elevation file
confFile = parameters[1].valueAsText #User specified configuration file

args = (ninjaPath, "--elevation_file", imgFile, "--config_file", confFile)

runfile = subprocess.Popen(args,stdout= subprocess.PIPE, bufsize = -1) #Run windninja cli


output = runfile.stdout.read()
if output is None:
    messages.AddMessage("Results: None returned\n")
    messages.AddMessage("Results:\n" + output)

The CLI takes the elevation .tif and the configuration file, does its magic, and creates an output ASCII file as a result. However, the output ASCII file is always written to the same location as the input elevation file. A query of the location of the specified elevation file on the server returns:

enter image description here

which is the unique jobs id folder for the task. The script runs successfully on a local machine and takes ~20 seconds to complete. It takes about ~2 seconds to complete on the server, and a query of the unique jobs id folder afterwards shows no resulting ASCII. So here comes my list of questions:

  1. Does a copy of the user specified elevation file actually exist in the unique jobs id folder?

  2. Are there any arcpy tools that would allow me to copy the elevation and configuration files to a known location on the server (say the scratch workspace for example), and then run the CLI on those copies?

  3. How can I return the resulting ASCII (once I can get the script to create it on the server, and locate where it's created) from the geoprocessing service to my local machine?

  • Do you need to run it in a subprocess? If not, I'd go back and try it without. Your 2 second comment makes it sound like the task launches it, and thats it. It doesn't wait for a respond. (Can you see it running in task manager on the server?) Additionally, keep in mind .exe arent pushed to the server when you publish. Its on you (the service deployer) to make sure that .exe lives on the server and is accessible/usable by the server. – KHibma Sep 26 '14 at 21:10
  • Thanks for the comment. I'll try it without the subprocess, and see if it shows up in task manager. We do have the .exe on the server, so that's not the issue. Thanks again-- – GISUser9 Sep 26 '14 at 21:27

Instead of using PIPE in the subprocess.Popen, you can use a file path to save the output. You can create the path by using the arcpy.CreateScratchName() (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/CreateScratchName/000v0000001z000000/).

After the subprocess runs and you have the output in the file, you might set the output parameter like arcpy.SetParameterAsText(2, outpath), assuming you have the file path in outpath. ArcGIS is supposed to handle streaming the file back to the client, once the output parameter is set.

| improve this answer | |

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