Reputation: 97
I'm using the following code to get the output of an nslookup command:
Dim oShell
Dim strCmdOutput
If DO_DEBUG="n" Then On Error Resume Next
Set oShell = WScript.CreateObject ("WScript.Shell")
Set shellOut = oShell.Exec("cmd.exe /C nslookup www.bbc.co.uk 8.8.8.8")
strCmdOutput = shellOut.StdOut.ReadAll()
WScript.Scho strCmdOutput
The output I get into strCmdOutput is different from the output I get by manually running the command.
For example, manually I get:
Server: google-public-dns-a.google.com Address: 8.8.8.8 Non-authoritative answer: Name: www.bbc.net.uk Addresses: 212.58.244.71 212.58.246.95 Aliases: www.bbc.co.uk
And using the script I get:
Server: google-public-dns-a.google.com Address: 8.8.8.8 Name: www.bbc.net.uk Addresses: 212.58.244.69 212.58.246.93 Aliases: www.bbc.co.uk
The outputs can vary wildly, is there a way I can get the outputs to match?
Upvotes: 1
Views: 241
Reputation: 200503
The line Non-authoritative answer:
is written to STDERR, so you need to merge that into STDOUT to get the entire output.
Change the line
Set shellOut = oShell.Exec("cmd.exe /C nslookup www.bbc.co.uk 8.8.8.8")
to
Set shellOut = oShell.Exec("cmd.exe /C nslookup www.bbc.co.uk 8.8.8.8 2>&1")
and the problem will disappear.
Upvotes: 4