运行 一个命令并在 vbscript 中捕获输出
Run a command and capture the output in vbscript
我正在尝试 运行 以下命令并使用 VBscript return 它的输出:
dir /A-d "C:\Windows\Minidump" | find /c "/"
我有以下脚本但它不起作用(可能是因为“字符:
Wscript.Echo runCMD("dir /A-d "C:\Windows\Minidump" | find /c "/"")
Function runCMD(strRunCmd)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strRunCmd)
strOut = ""
Do While Not objExec.StdOut.AtEndOfStream
strOut = strOut & objExec.StdOut.ReadLine()
Loop
Set objShell = Nothing
Set objExec = Nothing
runCMD = strOut
End Function
关于如何实现这一点有什么建议吗?
dir
是固有的;你需要 %comspec%
.
双引号在VBScript中需要用双引号转义:
Wscript.Echo runCMD("%comspec% /c dir /A-d ""C:\Windows\Minidump"" | find /c ""/""")
我正在尝试 运行 以下命令并使用 VBscript return 它的输出:
dir /A-d "C:\Windows\Minidump" | find /c "/"
我有以下脚本但它不起作用(可能是因为“字符:
Wscript.Echo runCMD("dir /A-d "C:\Windows\Minidump" | find /c "/"")
Function runCMD(strRunCmd)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strRunCmd)
strOut = ""
Do While Not objExec.StdOut.AtEndOfStream
strOut = strOut & objExec.StdOut.ReadLine()
Loop
Set objShell = Nothing
Set objExec = Nothing
runCMD = strOut
End Function
关于如何实现这一点有什么建议吗?
dir
是固有的;你需要%comspec%
.双引号在VBScript中需要用双引号转义:
Wscript.Echo runCMD("%comspec% /c dir /A-d ""C:\Windows\Minidump"" | find /c ""/""")