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())
這將在活動文檔的當前點處的命令的輸出粘貼。
請注意,如果該命令發出幾行,「文本導入」對話框將彈出(我不知道如何防止)。