question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Note: It is debatable what console encoding should apply when remoting into a Window machine - the caller’s or the target machine’s - but (effectively) using ANSI encoding - rather than the OEM code page, as is still the default on Windows - seems like the wrong choice.

Curiously, Windows PowerShell behaves this way too.

Steps to reproduce

Run on (PS Core) on Windows:

  • from an elevated session, to enable “loopback” remoting
  • make sure that the calling version is enabled for remoting
& {
  # Target the local machine.
  $htParams = @{ ('HostName', 'ComputerName')[$env:OS -eq 'Windows_NT'] = '.' }
  # On Windows, determine what edition / version to target remotely: use the caller's.
  if ($env:OS -eq 'Windows_NT') {
    $htParams['ConfigurationName'] = (('PowerShell.' + $PSVersionTable.PSVersion), 'microsoft.powershell')[$PSVersionTable.PSEdition -ne 'Core']
  }  
  Invoke-Command @htParams { if ($env:OS -eq 'Windows_NT') { chcp } else { $env:LANG }; [Console]::InputEncoding.WebName; [Console]::OutputEncoding.WebName, $OutputEncoding.WebName }
}

Expected behavior

Active code page: 437
ibm437   # [Console]::InputEncoding.WebName
ibm437   # [Console]::OutputEncoding.WebName
utf-8       # $OutputEncoding

Actual behavior

Active code page: 437
windows-1252   # !! *ANSI* code page
Codepage - 0   # !! *0* - but in effect seems to behave like ANSI
utf-8

Environment data

PowerShell Core 7.2.0-preview.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:61 (27 by maintainers)

github_iconTop GitHub Comments

3reactions
jborean93commented, May 17, 2021

Thanks all for sticking to this and working on a solution.

2reactions
jborean93commented, May 17, 2021

Thanks for the PR, I’ve been able to test it and can also confirm it fixes this particular problem. I also couldn’t find any side affects and things acted like they did before.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change default code page of Windows console to UTF-8
To change the codepage for the console only, do the following: Start -> Run -> regedit; Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command ...
Read more >
about Character Encoding - PowerShell
Describes how PowerShell uses character encoding for input and output of string data.
Read more >
Use a different character encoding
In this example scenario we will add support for using a different character encoding in the contents of SOAP requests. Out of the...
Read more >
How to use character encoding classes in .NET
This article explains how to use the classes that .NET provides for encoding and decoding text by using various encoding schemes.
Read more >
Character encoding on remote connections – strange ...
A character encoding determines which binary sequence is used to represent each letter, or other character. Many different ways to encode ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found