2011-06-15 87 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中它可以是美丽的:)任何应用