Skip to content

Commit 3d212c7

Browse files
author
LittleboyHarry
authored
Accept the owner advice in Utils.ps1
1 parent e439c99 commit 3d212c7

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/Utils.ps1

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,13 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) {
3232
# A native executable that writes to stderr AND has its stderr redirected will generate non-terminating
3333
# error records if the user has set $ErrorActionPreference to Stop. Override that value in this scope.
3434
$ErrorActionPreference = 'Continue'
35-
try {
36-
[Console]::OutputEncoding = [Text.Encoding]::UTF8
37-
& $cmd
38-
try {
39-
[Console]::OutputEncoding = $currentEncoding
40-
}
41-
catch [System.IO.IOException] {}
42-
}
43-
catch [System.IO.IOException] {
44-
& $cmd
45-
}
35+
36+
try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 } catch [System.IO.IOException] {}
37+
& $cmd
4638
}
4739
finally {
40+
try { [Console]::OutputEncoding = $currentEncoding } catch [System.IO.IOException] {}
41+
4842
# Clear out stderr output that was added to the $Error collection, putting those errors in a module variable
4943
if ($global:Error.Count -gt $errorCount) {
5044
$numNewErrors = $global:Error.Count - $errorCount

0 commit comments

Comments
 (0)