Jump to content

Attempting to parse multiline command stderr output


kevev
 Share

Recommended Posts

Howdy!

I am attempting to parse the stderr output of ffmpeg and store it into an array that will be pushed to a combobox. I have the full output example below.

 

Original input:

[libndi_newtek @ 000001f53af6af40] Found 3 NDI sources:
[libndi_newtek @ 000001f53af6af40]     'PC-NAME (Remote Connection 1)'    'ndi-app:PC-NAME%20(Remote%20Connection%201)'
[libndi_newtek @ 000001f53af6af40]     'PC-NAME (NDI - Output 1)'    '192.168.1.201:5961'
[libndi_newtek @ 000001f53af6af40]     'ANOTHER-PC (NDI - Output 3)'    '192.168.1.201:5962'
dummy: Immediate exit requested
 

Needed output:

PC-NAME (Remote Connection 1)
PC-NAME (NDI - Output 1)
ANOTHER-PC (NDI - Output 3)

 

My current code is here:

 

$iPID = Run(@ComSpec & ' /C "ffmpeg.exe -hide_banner -f libndi_newtek -find_sources 1 -i dummy"', @ScriptDir, @SW_HIDE, $STDERR_CHILD)
ProcessWaitClose($iPID)
$sDirtyOutput = StderrRead($iPID)
;This one gives me the columns I want, but the strings are still surrounded by single quotes " ' ".
;$sOutput = StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sDirtyOutput, ".*Found\ \d\ NDI\ sources:", ""), "dummy:\ Immediate\ exit\ requested", ""), "\[.*\]", "")
; This one gives no output.
$sOutput = StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sDirtyOutput, ".*Found\ \d\ NDI\ sources:", ""), "dummy:\ Immediate\ exit\ requested", ""), "\[.*\]", ""), "(?<=\047).*?(?=\047)", "")
$aOutputArray = StringSplit($sOutput, @CRLF)
GUICtrlSetData($aOutputArray, $sOutput & @CRLF)
;Remove blank lines from the Array.
For $i = UBound($aOutputArray) - 1 To 0 Step -1
        If $aOutputArray[$i] = "" Then
                _ArrayDelete($aOutputArray, $i)
        EndIf
        Next
        _ArrayDisplay($aOutputArray)

 

The output I get is:

''''

''''

''''

Edited by kevev
More info
Link to comment
Share on other sites

Maybe this :

#include <Array.au3>

Local $sText = "[libndi_newtek @ 000001f53af6af40] Found 3 NDI sources:" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'PC-NAME (Remote Connection 1)'    'ndi-app:PC-NAME%20(Remote%20Connection%201)'" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'PC-NAME (NDI - Output 1)'    '192.168.1.201:5961'" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'ANOTHER-PC (NDI - Output 3)'    '192.168.1.201:5962'" & @CRLF & _
"dummy: Immediate exit requested"

Local $aArray = StringRegExp($sText,"'(PC-NAME.+?|ANOTHER-PC.+?)'", 3)
_ArrayDisplay($aArray)

 

Link to comment
Share on other sites

1 hour ago, Nine said:

Maybe this :

#include <Array.au3>

Local $sText = "[libndi_newtek @ 000001f53af6af40] Found 3 NDI sources:" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'PC-NAME (Remote Connection 1)'    'ndi-app:PC-NAME%20(Remote%20Connection%201)'" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'PC-NAME (NDI - Output 1)'    '192.168.1.201:5961'" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'ANOTHER-PC (NDI - Output 3)'    '192.168.1.201:5962'" & @CRLF & _
"dummy: Immediate exit requested"

Local $aArray = StringRegExp($sText,"'(PC-NAME.+?|ANOTHER-PC.+?)'", 3)
_ArrayDisplay($aArray)

 

Thank You. I will not always get the same PC name. I really need the 2nd column text.

Link to comment
Share on other sites

PC-NAME/ANOTHER-PC are always in upper case ?  Rest are always in lower case ?

#include <Array.au3>

Local $sText = "[libndi_newtek @ 000001f53af6af40] Found 3 NDI sources:" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'PC-NAME (Remote Connection 1)'    'ndi-app:PC-NAME%20(Remote%20Connection%201)'" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'PC-NAME (NDI - Output 1)'    '192.168.1.201:5961'" & @CRLF & _
"[libndi_newtek @ 000001f53af6af40]     'ANOTHER-PC (NDI - Output 3)'    '192.168.1.201:5962'" & @CRLF & _
"dummy: Immediate exit requested"

Local $aArray = StringRegExp($sText,"'([A-Z].+?)'", 3)
_ArrayDisplay($aArray)

If that does not work, please provide some REAL results that we can actually work with...

Link to comment
Share on other sites

This should match any PC Name (regardless of capitalization) as long as the line structure follows your example.

#include <Array.au3>
Local $sText =  "[libndi_newtek @ 000001f53af6af40] Found 3 NDI sources:" & @CRLF & _
                "[libndi_newtek @ 000001f53af6af40]     'PC-NAME (Remote Connection 1)'    'ndi-app:PC-NAME%20(Remote%20Connection%201)'" & @CRLF & _
                "[libndi_newtek @ 000001f53af6af40]     'PC-NAME (NDI - Output 1)'    '192.168.1.201:5961'" & @CRLF & _
                "[libndi_newtek @ 000001f53af6af40]     'ANOTHER-PC (NDI - Output 3)'    '192.168.1.201:5962'" & @CRLF & _
                "[libndi_newtek @ 000001f53af6af40]     'PC-Name2 (NDI - Output 3)'    '192.168.1.201:5962'" & @CRLF & _
                "[libndi_newtek @ 000001f53af6af40]     'Whatever PC-Name (NDI - Output 3)'    '192.168.1.201:5962'" & @CRLF & _
                "[libndi_newtek @ 000001f53af6af40]     'unknown'    '192.168.1.201:5962'" & @CRLF & _
                "dummy: Immediate exit requested"

Local $aArray = StringRegExp($sText,"\].*?'(.+?)'", 3)
_ArrayDisplay($aArray)

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
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
 Share

  • Recently Browsing   0 members

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