Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python打印缓冲_Python_Printing_Executable_Arcgis - Fatal编程技术网

Python打印缓冲

Python打印缓冲,python,printing,executable,arcgis,Python,Printing,Executable,Arcgis,让我重新表述我先前的问题。 我刚刚用pythong作为脚本语言在ArcGIS中创建了一个工具。该工具使用subprocess.popen执行(运行)外部程序。当我从ArcGSIS运行该工具时,会出现一个仅显示以下内容的窗口 Executing: RunFLOW C:\FLOW C:\FLOW\FLW.bat Start Time: Mon Nov 30 16:50:37 2009 Running script RunFLOW... Completed script RuFLOW... Execu

让我重新表述我先前的问题。 我刚刚用pythong作为脚本语言在ArcGIS中创建了一个工具。该工具使用subprocess.popen执行(运行)外部程序。当我从ArcGSIS运行该工具时,会出现一个仅显示以下内容的窗口

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)
ERROR 999998: There are no more files.
当我从命令窗口运行相同的程序时,它会打印一个充满信息的屏幕(日期、迭代次数等)。我想在从ArcGIS运行模型后显示的窗口中查看所有这些信息,以及当前正在打印的内容。 我试过打印、通讯、刷新,但没能做到。有什么建议吗

当我现在运行脚本时,它会运行可执行文件,但它会给出如下错误

# 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)
ERROR 999998: There are no more files.

谢谢

我对ArcGIS一无所知,所以我可能在这里暗中拍摄,但是……如果你想要stdout,你通常不想要
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
未连接,并导致脚本出于某种原因退出。

我不确定您是否意识到这一点,但我使用:

gp.AddMessage('blah blah')

获取要显示在ArcGIS处理窗口中的消息。它是地理处理器对象的一种方法,即用Python导入以访问ArcGIS引擎的库。如果您正在执行任何地理处理,您可能已经导入了此库。

1。请省略诸如“让我重新表述我以前的问题”之类的令人困惑和不相关的垃圾。然后,请查看页面右侧的格式提示。@Mesut:重新格式化您的问题:请参阅编辑器帮助以了解如何执行代码块。我尝试在p=subprocess.Popen(Flow_bat,shell=True,stdout=subprocess.PIPE,stderr=subprocess.stdout)下面为p.stdout.readlines()中的行添加脚本:print line retval=p.wait()使用此脚本,我的程序将被执行(可以从putputs检查),但它仍然没有在我的收费进度窗口中打印命令窗口信息。我尝试了stdout\u value=p.stdout.read()并将其打印出来,但也不起作用。还有其他建议吗?我不确定还有什么建议。我没有进入ArcGIS的权限,我有点盲目飞行。