Jump to content

getting digits from stdout


gcue
 Share

Recommended Posts

hello world

i am trying to get the following digits -7.670000 from the following stdout (the first mention of -7.670000 is the one im after):

Quote

c:\users\smith\desktop\04 Life on Mars-.mp3
Recommended "Track" dB change: -7.670000
Recommended "Track" mp3 gain change: -5
Max PCM sample at current gain: 34042.576896
Max mp3 global gain field: 210
Min mp3 global gain field: 86


Recommended "Album" dB change for all files: -7.670000
Recommended "Album" mp3 gain change for all files: -5

stringbetween might be a little tricky because the numbers vary.  i have also tried stringregexp but i am not getting good results either

#include <AutoItConstants.au3>
#include <array.au3>
$msg_normal = 0


$mp3gain_dir = "C:\Users\smith\Downloads\mp3gain-win-full-1_2_5"
$mp3_path = "c:\users\smith\desktop\04 Life on Mars-.mp3"

Local $iPID = Run(@ComSpec & ' /c mp3gain.exe "' & $mp3_path & '"', $mp3gain_dir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Local $sOutput = ""
    While 1
        $sOutput = StdoutRead($iPID)
        If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
            ExitLoop
        EndIf

        if $sOutput = "" then ContinueLoop

;~         debug($sOutput)

        $rec_track_db_change = StringRegExp($sOutput, "db change: -([\d]*)", 3)
        debug($rec_track_db_change)
    WEnd

Func Debug($variable1 = "", $variable2 = "", $variable3 = "", $variable4 = "", $variable5 = "")

;~  #include <array.au3>
;~  $msg_normal = 0

    If IsArray($variable1) Or IsArray($variable2) Then
        If IsArray($variable1) Then _ArrayDisplay($variable1, $variable2)
        If IsArray($variable2) Then _ArrayDisplay($variable2, $variable1)
    Else
        $variable = ""

        If $variable1 <> "" Then $variable &= $variable1 & @CRLF
        If $variable2 <> "" Then $variable &= $variable2 & @CRLF
        If $variable3 <> "" Then $variable &= $variable3 & @CRLF
        If $variable4 <> "" Then $variable &= $variable4 & @CRLF
        If $variable5 <> "" Then $variable &= $variable5 & @CRLF

        $variable = StringStripWS($variable, 2)

        ClipPut($variable)

        MsgBox($msg_normal, "Debug", $variable)
    EndIf

EndFunc   ;==>Debug

as always any help is greatly appreciated!!!

Link to comment
Share on other sites

@gcue
\d is a metacharacter, so it doesn't need the square brackets, which are used with ranges, like A-Z, 0-9, and so on.
Then, since you need to capture the dot too, you need to specify that in the pattern, and so, you should do something like this:

#include <Array.au3>
#include <StringCostants.au3>

Global $strString = 'Recommended "Track" dB change: -7.670000' & @CRLF & _
                    'Recommended "Track" mp3 gain change: -5' & @CRLF & _
                    'Max PCM sample at current gain: 34042.576896' & @CRLF & _
                    'Max mp3 global gain field: 210' & @CRLF & _
                    'Min mp3 global gain field: 86' & @CRLF & _
                    'Recommended "Album" dB change for all files: -7.670000' & @CRLF & _
                    'Recommended "Album" mp3 gain change for all files: -5"'

_ArrayDisplay(StringRegExp($strString, "(?m)(-?\d{1,}\.?\d*)", $STR_REGEXPARRAYGLOBALMATCH))

Comments:

Spoiler

(?m): option multiline.
\d: metacharacter to "capture" a digit ([0-9]);
{1,}: quantifier. "Capture" the previous character from 1 to N times;
\ : backslash. Backslash is used to treat a metacharacter (the dot) literally;
.: metacharacter to "capture" every character except the newline (it does capture the newline when the option ?s is enabled);
?: quantifier, lazy. "Capture from 0 to 1 time" the previous character.
\d: metacharacter to "capture" digits ([0-9]);
*: quantifier. "Capture" the previous character from 0 to N times.

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

hmm missing the minus on there :)  (note: sometimes the minus will be there and sometimes it wont)

tried plugging in w or W in different spots but getting really weird results

thank you very much for your help!!

Link to comment
Share on other sites

@gcue
Edited the previous post :)

\w is used when you want to "capture" a word character, which is in the range [a-zA-Z0-9_];
\W is used when you want to capture anything that is NOT a word character.
When you need to "capture" digits only, then use \d, and nothing else :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • 4 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...