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 :-

<<Code>>

strTarget = “www.google.com”
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
Else
msgbox “Failed”
End If

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

<</Code>>

Advertisements

Eat, Sleep, Automate. REPEAT !

Tagged with: , , , , , ,
Posted in Awesum Stuff
2 comments on “How to Read Command Line Output with VBScript ?
  1. Ashutosh says:

    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 .

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Blog Stats
  • 168,130 hits
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 796 other followers

%d bloggers like this: