How to Read Command Line Output with VBScript ?

We can read the output of a command which is executed on the command prompt with VBS. As an application of this concept, I used it to find out the IP address of a website and check whether its down or not :-


strTarget = “”
Set objShell = CreateObject(“WScript.Shell”)
Set objExec = objShell.Exec(“ping -n 2 ” & strTarget)
blank = LCase(objExec.StdOut.ReadLine)
strPingResults = LCase(objExec.StdOut.ReadAll)
split1 = split(strPingResults)
tempIP = split1(2)
ipAddress= mid(tempIP,2,(len(tempIP)-2))

Set objRegEx = CreateObject(“VBScript.RegExp”)

objRegEx.Global = True
objRegEx.Pattern = “\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}”

Set colMatches = objRegEx.Execute(ipAddress)

If colMatches.Count > 0 Then
msgbox ipAddress
msgbox “Failed”
End If

If Instr(1,strPingResults,”0% loss”,1)>0 Then
msgbox “Website is Up”
msgbox “Website is down”
End If



2 thoughts on “How to Read Command Line Output with VBScript ?

  1. Hey Harshit ,
    In the Script, we are communicating with QC to update the Test results each time a Test case runs .
    So my requirement is to find out the QC – URL which is dynamic and keeps on changing.

    Can you suggest something that can help me find this URL (maybe in the hidden mode) without having the script to follow the conventional approach of opening IE and entering “http:qc ” and then once the dynamic URL comes in , and using the get URL property to find the URL .

    1. Hi Ashutosh,

      I think there is a load balancer implemented on the QC URL. You won’t be able to figure it out with pinging, so the above code would not work. You can use the following code :-

      Set IE = CreateObject(“InternetExplorer.Application”)

      ‘IE.visible = 1


      IE.navigate websiteName

      Wscript.Sleep 5000

      msgbox IE.document.url

      For more details, you can visit one of my posts :-

      Please let me know if this works for you.

      Harshit Kohli

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s