Skip to content

Commit

Permalink
Improve output encoding handling for winget validation in SandboxTest…
Browse files Browse the repository at this point in the history
….ps1
  • Loading branch information
Utesgui committed Feb 4, 2025
1 parent 88e8892 commit fa2a167
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion scripts/archive/misc/SandboxTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,21 @@ if (!$SkipManifestValidation -and ![String]::IsNullOrWhiteSpace($Manifest)) {
Invoke-CleanExit -ExitCode 3
}
Write-Information "--> Validating Manifest"
$validateCommandOutput = winget.exe validate $Manifest


$validateCommandOutput =
& {
# Store current output encoding setting
$prevOutEnc = [Console]::OutputEncoding
# Set [Console]::OutputEncoding to UTF-8 since winget uses UTF-8 for output
[Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()

winget.exe validate $Manifest

# Reset the encoding to the previous values
[Console]::OutputEncoding = $prevOutEnc
}

switch ($LASTEXITCODE) {
'-1978335191' {
($validateCommandOutput | Select-Object -Skip 1 -SkipLast 1) | Write-Information # Skip the first line and the empty last line
Expand Down

0 comments on commit fa2a167

Please sign in to comment.