如何从cmd获取变量并在vbscript中显示 - Vbscript [英] How to get a variable from cmd and show it in vbscript - Vbscript

查看:31
本文介绍了如何从cmd获取变量并在vbscript中显示 - Vbscript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i'm a beginner of vbscript , i need you help , my question is how do i do to get a variable from cmd and show it in vbscript for example get a ping from www.google.com and show it in a msgbox in vbscript help me code :

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

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

Get that output and show it in a msgbox later , help me

推荐答案

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

Here an example of how to do that. The response of the ping that is checked is in Dutch but that doesn't matter for your case.

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.

An advise though, don't begin scripting in vbscript, it's a dead end. Choose some modern scripting language like Python or still better for beginners: Ruby.

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

Be sure to use cscript as engine in stead of wscript, execute the following to set that as default.

wscript //H:Cscript

你的 vbscript 就是一行

Your vbscript is then one single line

puts `ping www.google.com`

这篇关于如何从cmd获取变量并在vbscript中显示 - Vbscript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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