Title: Stdin (standard input) for interactive external console programs is not set to the console's character encoding in the console/terminal host · Issue #10907 · PowerShell/PowerShell · GitHub
Open Graph Title: Stdin (standard input) for interactive external console programs is not set to the console's character encoding in the console/terminal host · Issue #10907 · PowerShell/PowerShell
X Title: Stdin (standard input) for interactive external console programs is not set to the console's character encoding in the console/terminal host · Issue #10907 · PowerShell/PowerShell
Description: Note: #10824 fixed the issue for stdout (standard output). When invoking external programs, the encoding of their standard input stream should match that of the hosting console, as reflected in [Console]::InputEncoding - just like the st...
Open Graph Description: Note: #10824 fixed the issue for stdout (standard output). When invoking external programs, the encoding of their standard input stream should match that of the hosting console, as reflected in [Co...
X Description: Note: #10824 fixed the issue for stdout (standard output). When invoking external programs, the encoding of their standard input stream should match that of the hosting console, as reflected in [Co...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/10907
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Stdin (standard input) for interactive external console programs is not set to the console's character encoding in the console/terminal host","articleBody":"Note: #10824 fixed the issue for _stdout_ (standard _output_).\r\n\r\nWhen invoking external programs, the encoding of their standard input stream should match that of the hosting console, as reflected in `[Console]::InputEncoding` - just like the standard _output_ encoding is set to `[Console]::OutputEncoding` (which was always the case in Windows PowerShell, but for PS Core was only recently fixed in #10824).\r\n\r\nNote: \r\n\r\n* This is for the case where stdin is _not_ redirected, where the external program reads input _interactively typed by the user_; by contrast, when PowerShell pipes input to an external program, the encoding specified in preference variable `$OutputEncoding` is used.\r\n\r\n* The problem also exists in Windows PowerShell.\r\n\r\n# Steps to reproduce\r\n\r\nRun the following on _Windows_, where `[Console]::InputEncoding` is (still) the OEM code page's encoding by default. \r\n\r\nInstall [dotnet-script]() for dynamic execution of C# code via an external program.\r\n\r\nRun the following and type or paste character `ü` when prompted:\r\n\r\n```powershell\r\n# Make (BOM-less) UTF8 the input encoding.\r\n[Console]::InputEncoding = [Text.Utf8Encoding]::new($false)\r\n\r\n# Execute dotnet-script with ad hoc code that reads bytes\r\n# from stdin.\r\ndotnet-script eval ((@'\r\n Console.WriteLine(\"Enter single character 'ü' and press ENTER\"); \r\n byte[] buf = new byte[2];\r\n using (Stream inStream = Console.OpenStandardInput())\r\n {\r\n inStream.Read(buf, 0, buf.Length);\r\n }\r\n Console.WriteLine(\"First 2 bytes read (should be 0xC3 0xBC for 'ü'):\");\r\n foreach (byte b in buf) { \r\n Console.WriteLine(\"0x\" + b.ToString(\"X\"));\r\n }\r\n'@\r\n) -replace '\"', '\\\"') | Tee-Object -Variable output\r\n\r\n$output[-2..-1] | Should -Be '0xC3', '0xBC'\r\n```\r\n\r\n# Expected behavior\r\n\r\nThe test should pass.\r\n\r\nThat is, the raw bytes read from stdin should reflect the UTF-8 encoding assigned to `[Console]::InputEncoding`, which is byte sequence `0xC3 0xBC` for `ü` ([LATIN SMALL LETTER U WITH DIAERESIS, `U+00FC`](http://www.fileformat.info/info/unicode/char/fc))\r\n\r\n# Actual behavior\r\n\r\nThe test fails: \r\n\r\n```\r\nExpected @('0xC3', '0xBC'), but got @('0x0', '0xD').\r\n```\r\n\r\nCuriously, a NUL byte was read instead of the typed character (`0xD` is just the CR char).\r\n\r\nThis shows that changing `[Console]::InputEncoding` had _some_ effect, but not the desired one.\r\n\r\nOn macOS, changing `[Console]::InputEncoding` is effectively _ignored_.\r\n\r\n# Environment data\r\n\r\n```none\r\nPowerShell Core 7.0.0-preview.5\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2019-10-26T21:19:09Z","url":"https://github.com/PowerShell/PowerShell/issues/10907"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:782d1163-825e-90b2-478a-de252ae07d72 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C06E:126CB9:278E6DE:3720F8C:6AFD4FFC |
| html-safe-nonce | fb44f673449cae8f3cb066c088533500e8ae62ed43dd106ab4453b8ee76afaa9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDZFOjEyNkNCOToyNzhFNkRFOjM3MjBGOEM6NkFGRDRGRkMiLCJ2aXNpdG9yX2lkIjoiMzcxMDIxOTEwNTQ0NjIxOTc3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 48c5fb5f670a34eb41c5a73bb8f9f455b5c262d9b33943173c8683cb0243ef3d |
| hovercard-subject-tag | issue:512886873 |
| 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/10907/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e164b8b6ce022eaeac119b6ad4969e2f0d26fa413fe900424f0de7983c49538d/PowerShell/PowerShell/issues/10907 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e164b8b6ce022eaeac119b6ad4969e2f0d26fa413fe900424f0de7983c49538d/PowerShell/PowerShell/issues/10907 |
| og:image:alt | Note: #10824 fixed the issue for stdout (standard output). When invoking external programs, the encoding of their standard input stream should match that of the hosting console, as reflected in [Co... |
| 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 | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| 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 | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width