使用命名管道连接到LibreOffice

时间:2012-03-19 16:57:03

标签: python openoffice.org named-pipes libreoffice uno

我可以很好地连接套接字,但我听说当一切都是本地的时候使用管道会更快,所以我想尝试一下,但我无法建立连接。

我用

启动Libre
 > soffice --headless --invisible --norestore --nodefault --nolockcheck --nofirstwizard --accept='pipe,name=ooo_pipe;urp;'

最小的python脚本应该可以工作但不是

import uno
from com.sun.star.connection import NoConnectException

pipe = 'ooo_pipe'
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
context = resolver.resolve("uno:pipe,name=%s;urp;StarOffice.ComponentContext" % pipe)

1 个答案:

答案 0 :(得分:4)

到目前为止我使用过套接字模式。只是通过cmd在我的机器上测试了管道:

/usr/lib/openoffice/program/soffice.bin -accept='pipe,name=foo;urp;StarOffice.ServiceManager' -nologo -headless -nofirststartwizard -invisible

$ lsof -c soffice|egrep "pipe|foo"
soffice.b 6698 user    3r  FIFO                0,8      0t0 15766935 pipe
soffice.b 6698 user    4w  FIFO                0,8      0t0 15766935 pipe
soffice.b 6698 user   15u  unix 0xffff88009773ed00      0t0 15767001 /tmp/OSL_PIPE_1000_foo

lsof显示有一个命名的socket foo,它可以在Python中获得连接。在实验开始时,有时候没有生成foo,因此引发了com.sun.star.connection.NoConnectException。但在此之后我无法重复此错误。

我们已经在生产中使用插座模式无头办公室多年,并且非常稳定和快速。似乎管道模式在这里仍然依赖于unix socket,所以我建议使用套接字模式。

相关问题