2009-12-01 110 views
1

讓我重新說明我以前的問題。 我剛剛在ArcGIS中使用pythong作爲腳本語言創建了一個工具。該工具使用subprocess.popen執行(運行)外部程序。當我從ArcGSIS運行該工具時,會出現一個僅顯示以下內容的窗口。Python打印緩衝

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) 

該腳本是如下

# 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) 

當我從命令窗口運行同一程序,它打印一個完整的信息(日期,迭代的數量等)的屏幕。我想在從ArcGIS運行模型之後出現的窗口中查看所有這些信息,以及它現在正在打印的內容。 我試過打印,溝通,沖洗但無法做到。有什麼建議麼?

當我運行該腳本,因爲它是現在,它運行的可執行文件,但如下

ERROR 999998: There are no more files. 

感謝

+0

1.請忽略混淆和無關的垃圾,如「讓我重述我以前的問題」。然後,請查看頁面右側的格式化提示。 – 2009-12-01 01:46:17

+0

@Mesut:重新格式化您的問題:請參閱編輯器幫助,瞭解如何執行代碼塊 – jkp 2009-12-01 01:48:53

+0

感謝您的格式化... – Mesut 2009-12-01 01:56:28

回答

0

我一無所知ArcGIS中給出了一個錯誤,所以我可以在被拍攝這裏的黑暗,但是...如果你想要標準輸出,你通常不需要communicate()方法。你想是這樣的:

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

communicate()方法用於交互有一個過程。從文檔:

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

我猜測,當ArcGIS中運行你的腳本stdin未連接,並使腳本退出的某些原因。

+1

感謝您的信息。我嘗試添加 下面的腳本p = subprocess.Popen(Flow_bat,shell = True,stdout = subprocess.PIPE,stderr = subprocess.STDOUT) .wait() 使用此腳本執行我的程序(可以從putputs中檢查它),但它仍然不打印我的收費進度窗口上的命令窗口信息。 我試過stdout_value = p.stdout.read()並打印它,但它也沒有工作。 還有其他建議嗎? – Mesut 2009-12-01 19:22:20

+0

我不確定還有什麼建議。我無法訪問ArcGIS,因爲我很盲目。 – larsks 2009-12-04 01:01:52

0

我不知道你是否意識到這一點或沒有,但我用:

gp.AddMessage('blah blah') 

得到的消息出現在ArcGIS中處理窗口。它是地理處理器對象的一種方法,即您在Python中導入以訪問ArcGIS引擎的庫。如果您正在執行任何地理處理,則您已經導入了此庫。