In visual studio I want a macro that takes the selected text, pipes it to a dos command, captures the resulting stream and replaces th开发者_如何学JAVAe selected text with it.
Something like this...
Dim objSel As TextSelection = DTE.ActiveDocument.Selection
objSel.Text = RunShellCommand("beautify.rb", objSel.Text)
..where I don't know how to implement RunShellCommand
.
It seems Shell("beautify.rb", 1)
would execute a command and return the output, in which case all I need is .. "How do you stream text to the shell command?"
I have a work around using AutoHotKey (an excellent tool) and changing beautify.rb
to take a file.
;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
Now any text field in any app with sql in it can be beautiful :)
精彩评论