views:

204

answers:

2

Let me rephrase my previous question. I just created a tool in ArcGIS using pythong as script language. The tool executes (runs) an outside program using the subprocess.popen. When I run the tool from ArcGSIS, a window appears that only shows the following.

Executing: RunFLOW C:\FLOW C:\FLOW\FLW.bat
Start Time: Mon Nov 30 16:50:37 2009
Running script RunFLOW...
Completed script RuFLOW...
Executed (RunFLOW) successfully.
End Time: Mon Nov 30 16:50:48 2009 (Elapsed Time: 11.00 seconds)

The script is as follows

# Import system modules
import sys, string, os, arcgisscripting, subprocess
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Read the parameter values:
#  1: input workspace
prj_fld = gp.GetParameterAsText(0)
Flow_bat = gp.GetParameterAsText(1)
os.chdir(prj_fld)
p=subprocess.Popen(Flow_bat,shell=True,stdout=subprocess.PIPE)
stdout_value = p.communicate()[0]
print '\tstdout:', repr(stdout_value)

When I run the same program from command window, it prints a screen full of information (date, number of iteration, etc.). I want to see all this information in the window that appears after I run the model from ArcGIS in addition to what it is being printing right now. I tried print, communicate, flush but couldn't be able to do it. Any suggestions?

When I run the script as it is right now, it runs the executable but it gives an error as follows

ERROR 999998: There are no more files.

Thanks

A: 

I know nothing about ArcGIS, so I may be shooting in the dark here, but...if you want stdout, you usually don't want the communicate() method. You want something like this:

p=subprocess.Popen(Flow_bat,shell=True,stdout=subprocess.PIPE)
stdout_value = p.stdout.read()

The communicate() method is used for interacting with a process. From the documentation:

Interact with process: Send data to stdin.  Read data from stdout
and stderr, until end-of-file is reached.  Wait for process to
terminate.

I'm guessing that when ArcGIS runs your script that stdin is not connected and causes the script to exit for some reason.

larsks
Thanks for the info. I tried added the script belowp=subprocess.Popen(Flow_bat,shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)for line in p.stdout.readlines(): print lineretval=p.wait()with this script my program is executed (can check it from the putputs) but still it doesnt print the command window information on my toll progress window.I tried stdout_value=p.stdout.read() and print it but it didnt work either.Any other suggestions?
Mesut
I'm not really sure what else to suggest. I don't have access to ArcGIS to I'm sort of flying blind.
larsks
A: 

I'm not sure if you are aware of this or not but I use:

gp.AddMessage('blah blah')

to get messages to appear in the ArcGIS processing window. Its a method of the geoprocessor object, the library you import in Python to access the ArcGIS engine. You would already have imported this library if you are doing any geoprocessing.

Casey