Sign in to follow this  
Followers 0
Decker87

StdOut for nbtstat command?

6 posts in this topic

Hi. I am trying to write a function to report a computer name by way of it's IP Address. This can be done in windows at the command prompt using the command NBTSTAT -A <IP Address>. I don't understand how to use standard output to get the output of that command into some AutoIT variables. Can someone show me how to read this command's output?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Modified from the help file on StdoutRead() :

#include <Constants.au3>

$nbtstat = Run(@ComSpec & " /c " & 'NBTSTAT -A 127.0.0.1', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$out = ''

While 1
    $line = StdoutRead($nbtstat)
    If @error Then ExitLoop
    $out &= $line & @CRLF
Wend
MsgBox(0, "test", $out )
Edited by danwilli

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Modified from the help file on StdoutRead() :

#include <Constants.au3>

$nbtstat = Run(@ComSpec & " /c " & 'NBTSTAT -A 127.0.0.1', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$out = ''

While 1
    $line = StdoutRead($nbtstat)
    If @error Then ExitLoop
    $out &= $line & @CRLF
Wend
MsgBox(0, "test", $out )
Do you get a weird MsgBox when you run this?

I get one with just the Title bar part and the "X" to close it.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Do you get a weird MsgBox when you run this?

I get one with just the Title bar part and the "X" to close it.

I didn't before, but now I do... It appears that something changed in StdoutRead().

It was sending too much data to the MsgBox, so it made the weird one you saw.

Had to add <If $line <> ''> to stop all the white space from being put into the string.

This works in latest version:

#include <Constants.au3>

$nbtstat = Run(@ComSpec & " /c " & 'NBTSTAT -A 127.0.0.1', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$out = ''

While 1
    $line = StdoutRead($nbtstat)
    If @error Then ExitLoop
    If $line <> '' Then $out &= $line & @CRLF
Wend
MsgBox(0, "test", $out )

Share this post


Link to post
Share on other sites

... This works in latest version: ...

Much better :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0