Jump to content

StringRegExp Help (Solved)


Subz
 Share

Recommended Posts

As part of a software package I need to capture exit codes from Microsoft .NET Framework log after the installation, I don't want to use browser automation as I just want to see if the installation was successful or not and if it requires a reboot to continue.  The third-party software won't continue until the .NET Framework has been installed, unfortunately the exit codes from using Run are all returning 0 even though the log file is reporting a reboot is required.  Using string functions at the moment but thought someone might know of a better way using regular expression?

:: Computer 1
</span>Final Result: Installation completed successfully with success code: (0x00000000), "The operation completed successfully.
" (Elapsed time: 0 00:00:00).<BR></span>

:: Compuer 2
</span>Final Result: Installation completed successfully with success code: (0x80070BC2), "The requested operation is successful. Changes will not be effective until the system is rebooted.
" (Elapsed time: 0 00:05:02).<BR></span>

:: Computer 3
</span>Final Result: Installation failed with error code: (0x80092004), "Cannot find object or property.
" (Elapsed time: 0 00:02:57).<BR></span>

Edited by Subz
Link to comment
Share on other sites

Does the "Final Result" message occur only once in any given Microsoft .NET Framework log file or do you need the last occurrence of the "Final Result" message?

Edited by TheXman
Link to comment
Share on other sites

Yes it only occurs once, it's also the last line of the page, in the body they use Javascript to reference the <span> tags.

It should be noted that after the blue text there is @CRLF before the closing quote(") as shown above.

Link to comment
Share on other sites

Here's a quick & dirty example of one way that it could be done :)

#include <Constants.au3>

example()

Func example()
    Const $MSG1 = '</span>Final Result: Installation completed successfully with success code: (0x00000000), "The operation completed successfully.' & @CRLF & '" (Elapsed time: 0 00:00:00).<BR></span>'
    Const $MSG2 = '</span>Final Result: Installation completed successfully with success code: (0x80070BC2), "The requested operation is successful. Changes will not be effective until the system is rebooted.' & @CRLF & '" (Elapsed time: 0 00:05:02).<BR></span>'
    Const $MSG3 = '</span>Final Result: Installation failed with error code: (0x80092004), "Cannot find object or property.' & @CRLF & '" (Elapsed time: 0 00:02:57).<BR></span>'

    ConsoleWrite(StringFormat("MSG1 successful       = %s", IsInstallSuccessful($MSG1)) & @CRLF)
    ConsoleWrite(StringFormat("MSG1 reboot required? = %s", IsRebootRequired($MSG1))    & @CRLF)

    ConsoleWrite(StringFormat("MSG2 successful       = %s", IsInstallSuccessful($MSG2)) & @CRLF)
    ConsoleWrite(StringFormat("MSG2 reboot required? = %s", IsRebootRequired($MSG2))    & @CRLF)

    ConsoleWrite(StringFormat("MSG3 successful       = %s", IsInstallSuccessful($MSG3)) & @CRLF)
    ConsoleWrite(StringFormat("MSG3 reboot required? = %s", IsRebootRequired($MSG3))    & @CRLF)
EndFunc

Func IsInstallSuccessful($sMsg)
    Return StringRegExp($sMsg, "Final Result: Installation completed successfully")
EndFunc

Func IsRebootRequired($sMsg)
    Return StringRegExp($sMsg, "Final Result: Installation completed successfully.*?Changes will not be effective until the system is rebooted")
EndFunc

Output:

MSG1 successful       = 1
MSG1 reboot required? = 0
MSG2 successful       = 1
MSG2 reboot required? = 1
MSG3 successful       = 0
MSG3 reboot required? = 0

 

Edited by TheXman
Link to comment
Share on other sites

#include<array.au3>

$str = fileread("test.txt")

$a = StringRegExp($str , '(Installation .*?) with .*? \((.+?)\), \"(.+?\.)' , 3)

_ArrayDisplay($a)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Local $s = '<span>Final Result: Installation completed successfully with success code: (0x00000000), '
      $s &= '"The operation completed successfully." (Elapsed time: 0 00:00:00).<BR></span>'

      $s = StringRegExpReplace($s, '.*(Final Result.*?)<.*', '$1')

      MsgBox(0, 'Result', $s)

; 1. [ .* ] run to first character wanted, to...
; 2. [ (Final Result.*?) ] capture any wanted character, to...
; 3. [ <.* ] finish from < to end of text document.
; 4. [ $1 ] output captured group.

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

@iamtheky Perfect thanks for that.

@TheXman Thanks for your input, I only posted 3 examples but there are a number of different Windows Update codes/messages.

@ripdad Thanks for your input as well, although I could only get the code you posted working above, however when I used it against the log file (3202 lines), it just showed the entire log.

Thanks again for all your input, appreciate the assistance.

Link to comment
Share on other sites

17 hours ago, Subz said:

I just want to see if the installation was successful or not and if it requires a reboot to continue.

If the "Final Result" is entirely on one line, this simple thing might work

#Include <Array.au3>

$txt = ":: Computer 1" & @crlf & _ 
    "</span>Final Result: Installation completed successfully with success code: (0x00000000), ""The operation completed successfully." & @crlf & _ 
    """ (Elapsed time: 0 00:00:00).<BR></span>" & @crlf & _ 
    @crlf & _ 
    ":: Compuer 2" & @crlf & _ 
    "</span>Final Result: Installation completed successfully with success code: (0x80070BC2), ""The requested operation is successful. Changes will not be effective until the system is rebooted." & @crlf & _ 
    """ (Elapsed time: 0 00:05:02).<BR></span>" & @crlf & _ 
    @crlf & _ 
    ":: Computer 3" & @crlf & _ 
    "</span>Final Result: Installation failed with error code: (0x80092004), ""Cannot find object or property." & @crlf & _ 
    """ (Elapsed time: 0 00:02:57).<BR></span>"
 Msgbox(0,"", $txt)

$res = StringRegExp($txt, 'Final Result:\h*(.+)', 3)

_ArrayDisplay($res)

 

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...