运行命令并在 vbscript 中捕获输出 [英] Run a command and capture the output in vbscript

查看:38
本文介绍了运行命令并在 vbscript 中捕获输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行以下命令并使用 VBscript 返回它的输出:

I am trying to run the following command and return the output of it using VBscript:

dir /A-d "C:\Windows\Minidump" | find /c "/"

我有以下脚本但它不起作用(可能是因为字符:

And I have the following script but it does not work (probably because of " charachters:

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

有关如何实现这一目标的任何建议?

Any suggestions on how to achieve this?

推荐答案

  1. dir 是内在的;你需要 %comspec%.
  2. 双引号需要在VBScript中用双双引号转义:

  1. dir is intrinsic; you need %comspec%.
  2. Double quotes need to be escaped by double double quotes in VBScript:

Wscript.Echo runCMD("%comspec% /c dir /A-d ""C:\Windows\Minidump"" | find /c ""/""")

这篇关于运行命令并在 vbscript 中捕获输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆