mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Set the output encoding to [Console]::OutputEncoding for native commands (#10824)
This commit is contained in:
@@ -1101,11 +1101,13 @@ namespace System.Management.Automation
|
||||
if (redirectOutput)
|
||||
{
|
||||
startInfo.RedirectStandardOutput = true;
|
||||
startInfo.StandardOutputEncoding = Console.OutputEncoding;
|
||||
}
|
||||
|
||||
if (redirectError)
|
||||
{
|
||||
startInfo.RedirectStandardError = true;
|
||||
startInfo.StandardErrorEncoding = Console.OutputEncoding;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -128,6 +128,18 @@ Describe "Native Command Processor" -tags "Feature" {
|
||||
$ps.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
It "OutputEncoding should be used" -Skip:(!$IsWindows -or !(Get-Command sfc.exe)) {
|
||||
|
||||
$originalOutputEncoding = [Console]::OutputEncoding
|
||||
try {
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::Unicode
|
||||
sfc | Out-String | Should -Not -Match "`0"
|
||||
}
|
||||
finally {
|
||||
[Console]::OutputEncoding = $originalOutputEncoding
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Open a text file with NativeCommandProcessor" -tags @("Feature", "RequireAdminOnWindows") {
|
||||
|
||||
Reference in New Issue
Block a user