1

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?

1
  • just to hi-lite the difference, one has "Non-authoritative answer:" and the other doesn't Commented Jul 6, 2017 at 11:39

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.