Help with os.spawnv

IamIan iansan at gmail.com
Thu Feb 9 18:48:35 EST 2006


I've had to migrate back to Python 2.1 and am now trying to use
os.spawnv to get around a memory leak (either in Python or ArcGIS or
both) in a geoprocessing script.

This script (Second Script) gets each Ascii file in the workspace,
converts it to a raster, sets the spatial reference, and hillshades it.
The script works on its own. In the Main Script I can successfully pass
parameters in a list, but no geoprocessing is ever initiated when using
os.spawnv. No errors are being thrown so I don't have a traceback to
post. Help getting this straightened out would be EXTREMELY
appreciated!


Main Script

# Import subprocess module
import os, sys

# Define arguments for subprocess
pyPath = "E:\\Python242\\python.exe"
pyScript = "E:\\Documents and
Settings\\Administrator\\Desktop\\Ian\\GIS\\Python\\subProcess2.py"
workspace = "E:\\GISTest"

# Get a list of ASCII files in the workspace for ASCII To Raster
conversion
filenames = os.listdir(workspace)
filenames = [filename.lower()
for filename in filenames
if (filename[-4:].lower() == ".asc" and filename[0] != "-" )]
for filename in filenames:
    # Define Img filename, truncating .asc from inAscii filename
    inAscii = workspace + "\\" + filename
    outImg = workspace + "\\" + filename[:-4] + ".img"

    # Create parameter list
    parameterList = []
    # First parameter is the name of the Python executable
    parameterList.append('python.exe')
    # Second parameter is the full path of the Python script
    parameterList.append(pyScript)
    # The following parameters are the arguments for the Batch script
    parameterList.append(filename)
    parameterList.append(inAscii)
    parameterList.append(outImg)
    parameterList.append(outHill)
    print parameterList
    # Run subprocess
    os.spawnv(os.P_WAIT, pyPath, parameterList)
    print parameterList

Second Script

I can't post this verbatim for work reasons, but basically it goes:

import sys, os, win32com.client, string
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
gp.SetProduct("ArcInfo")
gp.CheckOutExtension("Spatial")

# For each ASCII file, convert into IMG format
filename = sys.argv[1]
inAscii = sys.argv[2]
outImg = sys.argv[3]
outHill = sys.argv[4]

Do Ascii to raster conversion using inAscii, creating outImg

Set spatial reference

Hillshade using outImg, creating outHill

Convert each hillshade to IMG format, using outHill




More information about the Python-list mailing list