ahgittin commented on pull request #1143:
URL: https://github.com/apache/brooklyn-server/pull/1143#issuecomment-771586399


   This makes three output streams for winrm commands:
   
   * stdout = usual
   * xmlout = the full xml we get from powershell, pretty-printed (using 
@duncangrant 's recent work)
   * stderr = xmlout de-xml-ified filtered for Error stream messages
   
   For example, as per the new live test `testDifferentLogLevels` given the 
input script:
   
   ```
   $DebugPreference = "Continue"
   $VerbosePreference = "Continue"
   Write-Host "Log in Host Stream"
   Write-Output "Log in Success Stream"
   Write-Error "Log in Error Stream" 
   Write-Warning "Log in Warning Stream"
   Write-Verbose "Log in Verbose Stream"
   Write-Debug "Log in Debug Stream" 
   ```
   
   `stdout` has, both from winrm and in our ui:
   
   ```
   Log in Host Stream
   Log in Success Stream
   ```
   
   the actual `stderr` stream as returned from winrm has XML, which is not as 
helpful as people might wish stderr to be, and is not what the MS docs 
say(https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_output_streams?view=powershell-7.1);
 so we pretty format this and return it in an `xmlout` stream for the ui:
   
   ```
   #< CLIXML
   <Objs Version="1.1.0.1" 
xmlns="http://schemas.microsoft.com/powershell/2004/04";>
        <S S="Error">$DebugPreference = "Continue"_x000D__x000A_</S>
        <S S="Error">$VerbosePreference = "Continue"_x000D__x000A_</S>
        <S S="Error">Write-Host "Log in Host Stream"_x000D__x000A_</S>
        <S S="Error">Write-Output "Log in Success Stream"_x000D__x000A_</S>
        <S S="Error">Write-Error "Log in Error Stream" _x000D__x000A_</S>
        <S S="Error">Write-Warning "Log in Warning Stream"_x000D__x000A_</S>
        <S S="Error">Write-Verbose "Log in Verbose Stream"_x000D__x000A_</S>
        <S S="Error">Write-Debug "Log in Debug Stream" _x000D__x000A_</S>
        <S S="Error"> : Log in Error Stream_x000D__x000A_</S>
        <S S="Error">    + CategoryInfo          : NotSpecified: (:) 
[Write-Error], WriteErrorExcep _x000D__x000A_</S>
        <S S="Error">   tion_x000D__x000A_</S>
        <S S="Error">    + FullyQualifiedErrorId : 
Microsoft.PowerShell.Commands.WriteErrorExceptio _x000D__x000A_</S>
        <S S="Error">   n_x000D__x000A_</S>
        <S S="Error"> _x000D__x000A_</S>
        <S S="warning">Log in Warning Stream</S>
        <S S="verbose">Log in Verbose Stream</S>
        <S S="debug">Log in Debug Stream</S>
   </Objs>
   ```
   
   we then extract all the "Error" stream messages to return in our `stderr` 
stream in the ui _without_ XML, which contains the script we passed followed by:
   
   ```
    : Log in Error Stream
       + CategoryInfo          : NotSpecified: (:) [Write-Error], 
WriteErrorExcep 
      tion
       + FullyQualifiedErrorId : 
Microsoft.PowerShell.Commands.WriteErrorExceptio 
      n
   ```
   
   (it's still not as pretty as one might like, but it's a faithful extraction 
of the error stream from the xml (and yes, the crazy line breaks are part of 
what the stream returns, see the corresponding xml and note we've filtered out 
the `_x000D__x000A_`) -- expect there are powershell parameters one could set 
to get better info)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to