Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 10th, 2006, 12:05 AM
IamIan
Guest
 
Posts: n/a
Default 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.GpDisp atch.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

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles