Kimbal Robinson's answer作品,但使用文件的缺点。它比较慢(与仅使用内存相比),并且之后必须删除文件(尽管将它放在/ tmp中,它通常最终会自动删除)。
一种替代方法是通过剪贴板具有数据中转:
Dim myCommand As String
myCommand = "echo hello world"
Shell ("bash", 1, "-c "" " & myCommand & " | xclip -selection clipboard"" ", true)
' setting the 4th parameter to true ensures that the Shell function will wait until '
' the command terminates before returning '
' then paste the content of the clipboard '
Dim dh As Object
dh = createUnoService("com.sun.star.frame.DispatchHelper")
dh.executeDispatch(StarDesktop.CurrentFrame, ".uno:Paste", "", 0, Array())
这将在活动文档的当前点处的命令的输出粘贴。
请注意,如果该命令发出几行,“文本导入”对话框将弹出(我不知道如何防止)。