Error setting GP Properties in a Python Subprocess

787
1
06-30-2011 12:45 PM
WilliamSleavin
New Contributor
So I am using the following code to call another python routine which does some geoprocessing.

def runcmd(cmd, format='s'):
    import subprocess
    proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    stdout,stderr=proc.communicate()
    exit_code=proc.wait()
    return exit_code,stdout,stderr

Everything works fine until I launch the primary script from the toolbox.  It appears to me that if I try to set any environment variables (Workspace, Mask, Extent, etc) in the subroutine it throws an error.  The sub looks basically like this...

# Import system modules
import arcgisscripting, time, sys, os

gp = arcgisscripting.create(9.3)
gp.OverwriteOutput = 1
gp.CheckOutExtension("spatial")
try:
#now do some gp stuff

suggestions?

/wJs
0 Kudos
1 Reply
NilsRydh
New Contributor
Did you ever solve this?
I had a similar problem, which I solved by changing the current directory before calling subprocess:
os.chdir(scriptFolderPath)
subprocess.call(cmd)
0 Kudos