Sign in to follow this  
Followers 0
tbaror

Return values from stringregexp

7 posts in this topic

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)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The error values from StringRegExp are not in the return values, but they are in @error.

Also, $netstat &= StdoutRead($Cmd)

Edited by Manadar

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Manadar

Share this post


Link to post
Share on other sites

#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

Share this post


Link to post
Share on other sites

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

:D


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

Share this post


Link to post
Share on other sites

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

:D

:D thanks

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