Title: Make console windows fully UTF-8 by default on Windows, in line with the behavior on Unix-like platforms - character encoding, code page · Issue #7233 · PowerShell/PowerShell · GitHub
Open Graph Title: Make console windows fully UTF-8 by default on Windows, in line with the behavior on Unix-like platforms - character encoding, code page · Issue #7233 · PowerShell/PowerShell
X Title: Make console windows fully UTF-8 by default on Windows, in line with the behavior on Unix-like platforms - character encoding, code page · Issue #7233 · PowerShell/PowerShell
Description: PowerShell Core now commendably defaults to UTF-8 encoding, including when sending strings to external programs, as reflected in $OutputEncoding's default value. However, because the console-window shortcut file / taskbar entry still def...
Open Graph Description: PowerShell Core now commendably defaults to UTF-8 encoding, including when sending strings to external programs, as reflected in $OutputEncoding's default value. However, because the console-window...
X Description: PowerShell Core now commendably defaults to UTF-8 encoding, including when sending strings to external programs, as reflected in $OutputEncoding's default value. However, because the console-wi...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/7233
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make console windows fully UTF-8 by default on Windows, in line with the behavior on Unix-like platforms - character encoding, code page","articleBody":"PowerShell Core now commendably defaults to UTF-8 encoding, including when sending strings _to_ _external_ programs, as reflected in `$OutputEncoding`'s default value.\r\n\r\nHowever, because the console-window shortcut file / taskbar entry still defaults to the OEM code page implied by the legacy system locale (e.g. `437` on US-English systems), it misinterprets strings _from_ external programs; e.g., with Node.js installed:\r\n\r\n```powershell\r\nPSCoreOnWin\u003e $captured = '€' | node -pe \"require('fs').readFileSync(0).toString().trim()\"; $captured\r\nΓé¼ # !! node's UTF-8 output was misinterpreted.\r\n```\r\n\r\nThis currently requires the following _workaround_ (in addition to requiring the console window to use a TrueType font (true by default on Windows 10)):\r\n\r\n```powershell\r\n[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding\r\n```\r\n\r\n\u003csup\u003ePrepend `$OutputEncoding = ` to make a _Windows PowerShell_ console fully UTF-8-aware.\u003c/sup\u003e\r\n\r\nThe above implicitly switches to the UTF-8 code page (`65001`), as then reflected in `chcp`.\r\n\r\nThis obscure workaround shouldn't be necessary, and I think it would make sense for PowerShell to automatically set `[console]::InputEncoding` and `[console]::OutputEncoding` to (BOM-less) UTF-8 on startup.\r\n\r\n_Update_: When this issue was originally created, there was no mechanism for presetting code page `65001` (UTF-8) _system-wide_, which necessitated the awkward workaround. In recent versions of Windows 10 it _is_ now possible to switch to code page `65001` _as the system locale_ and therefore system-wide, although as of Windows 10 version 1909 that feature is still in _beta_ - see [this SO answer](https://stackoverflow.com/a/57134096/45375).\r\n\r\n * _Caveat_: In addition to defaulting the _OEM_ code page to `65001` in all console windows (including `cmd.exe` windows), this invariably also makes _Windows PowerShell_'s _ANSI_-encoding-default cmdlets default to UTF-8, notably `Get-Content` and `Set-Content`, which can be problematic from a backward-compatibility perspective. \r\nAdditionally, there is a _bug_ - [see below](https://github.com/PowerShell/PowerShell/issues/7233#issuecomment-640243647).\r\n\r\nThe change, which can also be made programmatically ([see below](https://github.com/PowerShell/PowerShell/issues/7233#issuecomment-640243647)), requires administrative privileges and a reboot.\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\nPowerShell Core 7.1.0-preview.3 on Windows 10\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-07-05T18:22:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":26},"url":"https://github.com/7233/PowerShell/issues/7233"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a6d913c0-dd39-32cc-dc83-ac24891e0095 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A81A:BFC9D:8BDFA0:CC7A82:6A589AC5 |
| html-safe-nonce | 7a0b3835e6e4a5b9fe2aa165e7604ffdeeba4e0af251f808984c9b28dc5df74c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODFBOkJGQzlEOjhCREZBMDpDQzdBODI6NkE1ODlBQzUiLCJ2aXNpdG9yX2lkIjoiOTA3MDIzMjU0MDE1ODY2MzM2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fb3c013be73ad93b44f1a0fa67097d59bdc209611e83539cdc1cee097fe44cc1 |
| hovercard-subject-tag | issue:338678675 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/7233/issue_layout |
| twitter:image | https://opengraph.githubassets.com/faed5b9c162fdc0c952b5f740f6183d11c0be0e4dbbd164e291a3ccf7ba411b3/PowerShell/PowerShell/issues/7233 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/faed5b9c162fdc0c952b5f740f6183d11c0be0e4dbbd164e291a3ccf7ba411b3/PowerShell/PowerShell/issues/7233 |
| og:image:alt | PowerShell Core now commendably defaults to UTF-8 encoding, including when sending strings to external programs, as reflected in $OutputEncoding's default value. However, because the console-window... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width