2012-03-19 178 views
3

我可以使用套接字連接就好了,但是我聽說當所有事情都是本地時,使用管道會更快,所以我想嘗試一下,但是我無法獲得連接。使用命名管道連接到LibreOffice

我開始與自由報

> 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) 
+2

你是什麼意思不起作用?你期望這個腳本做什麼?你看到了什麼呢? – subdir 2012-03-24 12:28:56

回答

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。但之後我無法重複這個錯誤。

我們已經在生產中使用了插座式無頭soffice幾年,其穩定性和速度足夠快。看來這裏的管道模式仍然依賴於unix套接字,所以我建議使用套接字模式。