Help with os.spawnv



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

.



Relevant Pages

  • Python and stale file handles
    ... I started back programming Python again after a hiatus of several ... regardless of how hard I try- it it starts with tailing a log file. ... I have a shell script constantly writes to the logfile.log... ... #Set the filename and open the file ...
    (comp.lang.python)
  • Re: Shell: run script
    ... |>>>python filename ... |>>>python filename.py ... you want to run a Python script as a program from any (other than the ... Python shell)? ...
    (comp.lang.python)
  • Re: sh: test: argument expected and /usr/bin/env
    ... taken as the first argument to the named binary, and the filename of the ... script is the second argument. ... You can set environment variables in Python. ... Jeff ...
    (comp.lang.python)
  • Re: perl to python
    ... sed and perl can let you do all that quick command line stuff. ... into a full blown script. ... scripts, call it from the python interpreter, whatever I need. ... If I stick to the traditional unix approach, ...
    (comp.lang.python)
  • Re: Learning Tkinter
    ... and how the command option is used to call the function callback. ... gui programming to see if the python programs I have written can be made ... search their computer for this file, execute the python code and then ... This is the meaning of the test on __name__: this magical variable is set to the string '__main__' if and only if the current script is the top-most one, i.e the one you ran python on. ...
    (comp.lang.python)