【问题标题】:How to get a variable from cmd and show it in vbscript - Vbscript如何从 cmd 获取变量并在 vbscript 中显示 - Vbscript
【发布时间】:2018-07-28 11:36:39
【问题描述】:

我是 vbscript 的初学者,我需要你的帮助,我的问题是如何从 cmd 获取变量并在 vbscript 中显示它,例如从 www.google.com 获取 ping 并将其显示在vbscript 中的 msgbox 帮助我编写代码:

dim cmd,x set cmd = createobject("wscript.shell") x= cmd.run("cmd /k ping www.google.com ",1,true)

获取该输出并稍后在 msgbox 中显示,帮助我

【问题讨论】:

    标签: vba vbscript adsutil.vbs


    【解决方案1】:

    这里有一个如何做到这一点的例子。 检查的 ping 响应是荷兰语,但这对您的情况无关紧要。

    Set objExec = CreateObject("WScript.Shell").exec("ping www.google.com")
    
    With objExec 
      Do While .Status = 0 
        WScript.Sleep 10 
        Do While Not .StdOut.AtEndOfStream 
          WScript.Echo .StdOut.ReadLine
          'Check the .StdErr to see if it is at the end of its
          'stream. If not, call ReadLine on it
          If Not .StdErr.AtEndOfStream Then
             .StdErr.ReadLine
          End If
        Loop
      Loop 
    End With
    

    不过,建议不要在 vbscript 中开始编写脚本,这是一条死胡同。 选择一些现代脚本语言,如 Python,或者更适合初学者:Ruby。

    请务必使用 cscript 作为引擎而不是 wscript,执行以下命令将其设置为默认值。

    wscript //H:Cscript
    

    你的 vbscript 就是一行

    puts `ping www.google.com`
    

    【讨论】:

    • 我想你的意思是 vbscript 代码?我发布了一个应该运行的简化版本(原始版本是荷兰版的 windows)对于 Ruby 代码,您需要先安装 Ruby rubyinstaller.org
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    相关资源
    最近更新 更多