Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 如何在vba中执行使用stdio和stdout的shell命令?_Visual Studio_Vba_Dos - Fatal编程技术网

Visual studio 如何在vba中执行使用stdio和stdout的shell命令?

Visual studio 如何在vba中执行使用stdio和stdout的shell命令?,visual-studio,vba,dos,Visual Studio,Vba,Dos,在VisualStudio中,我需要一个宏,该宏接收选定的文本,将其传输到dos命令,捕获结果流并用它替换选定的文本 像这样的 Dim objSel As TextSelection = DTE.ActiveDocument.Selection objSel.Text = RunShellCommand("beautify.rb", objSel.Text) …我不知道如何实现RunShellCommand 似乎Shell(“beautify.rb”,1)将执行一个命令并返回输出,在这种情况下

在VisualStudio中,我需要一个宏,该宏接收选定的文本,将其传输到dos命令,捕获结果流并用它替换选定的文本

像这样的

Dim objSel As TextSelection = DTE.ActiveDocument.Selection
objSel.Text = RunShellCommand("beautify.rb", objSel.Text)
…我不知道如何实现
RunShellCommand


似乎
Shell(“beautify.rb”,1)
将执行一个命令并返回输出,在这种情况下,我只需要。。“如何将文本流式传输到shell命令?”

我有一个解决方法,可以使用自动热键(一个优秀的工具)和更改
bestify.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的任何文本字段都可以很漂亮:)

我有一个解决方法,可以使用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的任何文本字段都可以很漂亮:)

您看过“Windows脚本主机对象模型”吗?您可以找到它的MSDN参考。您看过“Windows脚本主机对象模型”吗?您可以找到它的MSDN参考。