问题描述
|
在Visual Studio中,我希望有一个宏,它可以接收选定的文本,将其通过管道传递给dos命令,捕获结果流并用它替换选定的文本。
像这样
Dim objSel As TextSelection = DTE.ActiveDocument.Selection
objSel.Text = RunShellCommand(\"beautify.rb\",objSel.Text)
..我不知道如何实现RunShellCommand
。
似乎Shell(\"beautify.rb\",1)
将执行命令并返回输出,在这种情况下,我需要的只是.. \“如何将文本流式传输到Shell命令?\”
解决方法
我可以使用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的任何文本字段都可以很漂亮:)