tbaror Posted September 22, 2009 Share Posted September 22, 2009 Hello,i using StringRegExp to retrieve data from cmd netstat , i know how to build the expression but i don't now exactly to retrieve the data desired from it.i am sure its something easy and i missed it, i using code below please advice.thanks#include <Constants.au3> #include <Array.au3> dim $InitError [3] ,$netstat $cmd = Run(@ComSpec & " /c netstat -es " , @SystemDir, @SW_SHOW ,$STDERR_CHILD + $STDOUT_CHILD) While 1 $netstat = StdoutRead($Cmd) If @error Then ExitLoop Wend $tmp = StringRegExp($netstat, '(?:Errors\s*)([0-9]{1,3})', 2) $tmp2 = StringRegExp($netstat, '(?:Errors\s*[0-9]{1,3}\s*)([0-9]{1,3})', 2) MsgBox(1,"error","errors:"& $tmp &":"&$tmp2 & @CRLF) Link to comment Share on other sites More sharing options...
jvanegmond Posted September 22, 2009 Share Posted September 22, 2009 (edited) The error values from StringRegExp are not in the return values, but they are in @error. Also, $netstat &= StdoutRead($Cmd) Edited September 22, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
tbaror Posted September 22, 2009 Author Share Posted September 22, 2009 The error values from StringRegExp are not in the return values, but they are in @error.Also, $netstat &= StdoutRead($Cmd)Hi,can you explain it?thx Link to comment Share on other sites More sharing options...
jvanegmond Posted September 22, 2009 Share Posted September 22, 2009 (edited) #include <Constants.au3> #include <Array.au3> dim $InitError [3] ,$netstat $cmd = Run(@ComSpec & " /c netstat -es " , @SystemDir, @SW_SHOW ,$STDERR_CHILD + $STDOUT_CHILD) While 1 $netstat &= StdoutRead($Cmd) ;<= Change If @error Then ExitLoop Wend $tmp = StringRegExp($netstat, '(?:Errors\s*)([0-9]{1,3})', 2) MsgBox(0,"Real error", @error) ;<= Change Edited September 22, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
tbaror Posted September 22, 2009 Author Share Posted September 22, 2009 #include <Constants.au3> #include <Array.au3> dim $InitError [3] ,$netstat $cmd = Run(@ComSpec & " /c netstat -es " , @SystemDir, @SW_SHOW ,$STDERR_CHILD + $STDOUT_CHILD) While 1 $netstat &= StdoutRead($Cmd) ;<= Change If @error Then ExitLoop Wend $tmp = StringRegExp($netstat, '(?:Errors\s*)([0-9]{1,3})', 2) MsgBox(0,"Real error", @error) ;<= Change sorry :-), but again i didnt get it, i need the results from following output below i dont see how its related to "@err" C:\>netstat -es Interface Statistics Received Sent Bytes 3192481472 1396240779 Unicast packets 11421736 11319993 Non-unicast packets 3306209 9774 Discards 0 0 Errors 0 2 <- this section i need to have 2 values Unknown protocols 53351 thank you Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 22, 2009 Share Posted September 22, 2009 sorry :-), but again i didnt get it, i need the results from following output below i dont see how its related to "@err" C:\>netstat -es Interface Statistics Received Sent Bytes 3192481472 1396240779 Unicast packets 11421736 11319993 Non-unicast packets 3306209 9774 Discards 0 0 Errors 0 2 <- this section i need to have 2 values Unknown protocols 53351 thank you There is no such thing as "@err", there is an AutoIt macro @error which contains the error condition of previous operations. @error = 0 typically indicates no error. The return value from StringRegExp() with a flag = 2 is an array. In your expression, the array contains the entire line in [0] and the field you want in [1]. This displays the results: #include <Constants.au3> #include <Array.au3> Dim $InitError[3], $netstat $cmd = Run(@ComSpec & " /c netstat -es ", @SystemDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) While 1 $netstat &= StdoutRead($cmd) ;<= Change If @error Then ExitLoop WEnd $tmp = StringRegExp($netstat, '(?:Errors\s*)([0-9]{1,3})', 2) If @error = 0 Then _ArrayDisplay($tmp, "Results: $tmp") MsgBox(64, "Result", $tmp[1]) Else MsgBox(16, "Real error", @error) ;<= Change EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
tbaror Posted September 22, 2009 Author Share Posted September 22, 2009 There is no such thing as "@err", there is an AutoIt macro @error which contains the error condition of previous operations. @error = 0 typically indicates no error. The return value from StringRegExp() with a flag = 2 is an array. In your expression, the array contains the entire line in [0] and the field you want in [1]. This displays the results: #include <Constants.au3> #include <Array.au3> Dim $InitError[3], $netstat $cmd = Run(@ComSpec & " /c netstat -es ", @SystemDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) While 1 $netstat &= StdoutRead($cmd) ;<= Change If @error Then ExitLoop WEnd $tmp = StringRegExp($netstat, '(?:Errors\s*)([0-9]{1,3})', 2) If @error = 0 Then _ArrayDisplay($tmp, "Results: $tmp") MsgBox(64, "Result", $tmp[1]) Else MsgBox(16, "Real error", @error) ;<= Change EndIf thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now