【问题标题】:Getting command line output in VBScript (without writing to files)在 VBScript 中获取命令行输出(不写入文件)
【发布时间】:2011-07-20 14:01:07
【问题描述】:

我正在使用 VBScript,我的目标是能够用驱动器号替换我选择的路径。我需要 D 盘,如果它不可用,我需要检查它是否已经映射到正确的位置;如果不是,则通知用户。我发现了这个:http://technet.microsoft.com/en-us/library/ee156605.aspx,我正在尝试调整他们的第二个例子:

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c ping -n 3 -w 1000 157.59.0.1")
Do While Not objExecObject.StdOut.AtEndOfStream
    strText = objExecObject.StdOut.ReadLine()
    If Instr(strText, "Reply") > 0 Then
        Wscript.Echo "Reply received."
        Exit Do
    End If
Loop

(我的改编):

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c substr")
strText = ""

Do While Not objExecObject.StdOut.AtEndOfStream
    strText = strText & objExecObject.StdOut.ReadLine()
Loop

Wscript.Echo strText

然后我可能会搜索告诉 D 驱动器映射位置的字符串。我也试过objShell.Exec("subst"),但我仍然没有得到任何输出。有人对我可能做错了什么有任何想法吗?还是有更好的方法来讲述驱动器映射?谢谢,

213897

【问题讨论】:

    标签: windows vbscript subst drive-mapping


    【解决方案1】:

    您的脚本不起作用,因为您输入了错误的命令名称 - 它是 subst,而不是 substr

    【讨论】:

    • 哇,这真是好几天都想念的东西了……谢谢你的帮助 :)
    猜你喜欢
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多