gpt4 book ai didi

python - 使用命名管道连接到 LibreOffice

转载 作者:太空狗 更新时间:2023-10-30 02:34:10 25 4
gpt4 key购买 nike

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

我开始使用 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)

最佳答案

到目前为止,我一直使用套接字模式。刚刚通过命令在我的机器上测试了管道:

/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 显示有一个命名的套接字 foo 并且可以在 Python 中获取连接。在实验开始时,有时不会生成 foo,因此会引发 com.sun.star.connection.NoConnectException。但是之后我不能再重复这个错误了。

多年来,我们一直在生产中使用套接字模式的 headless office,它非常稳定且速度足够快。看来这里的管道模式还是依赖于unix socket,所以我建议使用socket模式。

关于python - 使用命名管道连接到 LibreOffice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9774410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com