import subprocess procs = [] cmd = "python foo.py arg1 arg2" proc = subprocess.Popen(cmd,shell=True) procs.append(proc)
def numRunningProcs(procs): numProcs = 0 for proc in procs: proc.poll() if proc.returncode == None: numProcs = numProcs + 1 return numProcs
Chris:
I tried running the first portion of your code, but the subprocess is not executing.
Here is my syntax to call the subprocess script:
cmd = "C:\\Python26\\ArcGIS10.0\\python.exe \\\\tgapparc01\\c$\\GIS Testing\\ReplaceSource.py full_path"
In the cmd line, full_path is the file that has the focus. File is stored in the full_path variable.
In the ReplaceSource.py script, I am trying to use the arcpy.GetParameterAsText(0) to bring in this argument. I'm not sure if this is the problem?
Could this issue possibly be how I am calling out the python executable and the python script that gets run in the subprocess?
Your assistance is greatly appreciated. Thanks.
Chris:
Can you please be a little bit more specific in what your code is looking for with the cmd = "python foo.py arg1 arg2" line? I still cannot get my code to evaluate the subprocess python script.
Does python refer to python.exe that has been installed on the computer that you are running this script from (e.g. c:\Python26\ArcGIS10.0\python.exe)?
Does foo.py refer tp the python script that you are running in the subprocess? If so, wouldn't you need to specify the full path to this file?
Are arg1 and arg2 variables from the primary script that you are sending to the subprocess script? If so, what is the syntax to get the subprocess script to accept these arguments? I ask because I am using arcpy.GetParameterAsText(0) to evaluate the single argument that I am trying to pass.
Your assistance is greatly appreciated. Thanks.
Chris:
I did see your last response and I moved the python script, that is called, to a folder with no spaces. No matter how I format the cmd line, the subprocess never gets executed.
import os, sys, string, arcpy import subprocess mxd_match = ".mxd" fileErrList = [] procs = [] Directory_Search = r"\\tgapparc00\e$\restore5\Planning_Run\Broken_Links\Test" for root, dirs, files in os.walk(Directory_Search): fListLength = len(files) if (fListLength != 0): n = 0 for f in files: if f.endswith(mxd_match): full_path = root + "\\" + str(f) cmd = "'C:\Python26\ArcGIS10.0\python.exe \\\\tgapparc01\\c$\\ReplaceSource.py' full_path" proc = subprocess.Popen(cmd,shell=True) procs.append(proc)