使用命名管道连接到LibreOffice

Nat*_*ons 4 python openoffice.org named-pipes uno libreoffice

我可以使用套接字进行连接,但是我听说在所有内容都是本地的情况下使用管道的速度更快,因此我想尝试一下,但无法建立连接。

我从Libre开始

 > soffice --headless --invisible --norestore --nodefault --nolockcheck --nofirstwizard --accept='pipe,name=ooo_pipe;urp;'
Run Code Online (Sandbox Code Playgroud)

而应该工作但不起作用的最低限度的最小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)
Run Code Online (Sandbox Code Playgroud)

okm*_*okm 6

I've used socket mode so far. Just tested pipe on my machine by the 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
Run Code Online (Sandbox Code Playgroud)

lsof shows that there is a named socket foo and its OK to get the connection in Python. At the start of the experiment, there were occasions that no foo is generated and hence com.sun.star.connection.NoConnectException was raised. But I can't repeat this error after that.

我们已经在生产中使用套接字模式无头办公室数年了,它非常稳定且足够快。似乎这里的管道模式仍然依赖于UNIX套接字,因此我建议使用套接字模式。