Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AllocConsole before initializing CLR to ensure codepage is correct #70

Merged
merged 1 commit into from
May 17, 2021

Conversation

SteveL-MSFT
Copy link
Member

Fix PowerShell/PowerShell#15128

Because PowerShell launched from pwrshplugin.dll via WinRM doesn't have a console attached, the console codepage is not setup correctly due to how .NET works. This means that ANSI/Unicode characters are incorrectly represented. Manually validated using tree command and this encoded command:

PS> $cmd = {
>>     [Console]::Out.WriteLine('café')
>> }
PS> $encCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($cmd.ToString()))
PS> $s = New-PSSession . -ConfigurationName powershell.7
PS> Invoke-Command -Session $s { pwsh -encodedcommand $using:enccommand }
café

@SteveL-MSFT SteveL-MSFT changed the title Use AllocConsole before initializing CLR to ensure console is attached Use AllocConsole before initializing CLR to ensure codepage is correct May 14, 2021
Copy link
Member

@JamesWTruher JamesWTruher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably emit something if the AllocConsole fails. Can we log?

@SteveL-MSFT
Copy link
Member Author

@JamesWTruher per the documentation, AllocConsole should really only fail if a console is already allocated, and if so, we can ignore that

@SteveL-MSFT
Copy link
Member Author

I manually verified the tree scenario now works on Win7 as well with the private

@adityapatwardhan adityapatwardhan merged commit e1cff37 into PowerShell:master May 17, 2021
@SteveL-MSFT
Copy link
Member Author

@andschwa the code page behavior is actually in .NET and is only documented in their source code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remote sessions targeting Windows machines unexpectedly use ANSI character encoding for external programs
5 participants