2011-06-15 88 views
2

在visual studio中,我想要一個接受選定文本的宏,將其導入到dos命令中,捕獲結果流並用它替換選定的文本。如何在使用stdio和stdout的vba中執行shell命令?

事情是這樣的......

Dim objSel As TextSelection = DTE.ActiveDocument.Selection 
objSel.Text = RunShellCommand("beautify.rb", objSel.Text) 

..where我不知道如何實現RunShellCommand

看起來Shell("beautify.rb", 1)會執行一個命令並返回輸出,在這種情況下,我所需要的只是..「如何將文本流式傳輸到shell命令?」

+0

你看的「Windows腳本宿主對象模型」的任何文本字段?你可以在這裏找到它的MSDN參考資料(http://msdn.microsoft.com/en-us/library/9bbdkx3k(v = VS.85).aspx)。 – 2011-06-15 11:09:07

回答

0

我有一個使用AutoHotKey(一個很好的工具)和改變beautify.rb採取文件的工作。

;window ctrl R - beautify sql 
#^R:: 
ClipSaved := ClipboardAll 
clipboard = ; Start off empty to allow ClipWait to detect when the text has arrived. 
Send ^c 
ClipWait ; Wait for the clipboard to contain text. 
FileDelete , c:\tmp\tmp_ahk_clip.txt 
FileAppend , %clipboard% , c:\tmp\tmp_ahk_clip.txt 
RunWait, %comspec% /c ""C:\...\Database\beautify.rb" c:\tmp\tmp_ahk_clip.txt > c:\tmp\tmp_ahk_clip_out.txt" ,,Hide 
FileRead, clipboard, c:\tmp\tmp_ahk_clip_out.txt 
Send ^v 
Clipboard := ClipSaved 
ClipSaved = ; Free the memory 
return 

現在在SQL中它可以是美麗的:)任何應用