Skip to content

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

Merged
Aditya Patwardhan (adityapatwardhan) merged 1 commit into
PowerShell:masterfrom
SteveL-MSFT:allocconsole
May 17, 2021
Merged

Aditya Patwardhan (adityapatwardhan) merged 1 commit into
PowerShell:masterfrom
SteveL-MSFT:allocconsole

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
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 Steve Lee (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
Copy Markdown
Contributor

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
Copy Markdown
Member Author

James Truher (@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
Copy Markdown
Member Author

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

@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit e1cff37 into PowerShell:master May 17, 2021
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Andy Jordan (@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