This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients eryksun, methane, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Date 2019-06-14.23:22:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAEfz+TzpUxtsdAHKGNTxZ4++aZnDGwuXfFULf3k32vYEh2_R=A@mail.gmail.com>
In-reply-to <1560534211.78.0.175735060516.issue37275@roundup.psfhosted.org>
Content
On Sat, Jun 15, 2019 at 2:43 AM Eryk Sun <report@bugs.python.org> wrote:
>
> Eryk Sun <eryksun@gmail.com> added the comment:
>
> > # Power Shell 6 (use cp65001 by default)
> > PS C:¥> python3 -c "print('おはよう')" > ps.txt
>
> PowerShell standard I/O redirection is different from any shell I've ever used. In this case, it runs Python with StandardOutput set to a handle for a pipe instead of a handle for the file. It decodes Python's output using whatever encoding is configured for input and re-encodes it with whatever encoding is configured for output.

I'm sorry,  I mixed my assumption.  I checked `os.device_encoding()` in cmd,
but forgot to check it on Power Shell.  All I said about Power Shell was just
my assumption and it was wrong.  And thank you for clarifying.

I confirmed writing UTF-8 to pipe cause mojibake, because Power Shell decodes
it using cp932.

```
PS C:\Users\inada-n> python3 -Xutf8 -c "import os,sys;
print(os.device_encoding(1), sys.stdout.encoding, file=sys.stderr);
print('こんにちは')" >x
None utf-8
PS C:\Users\inada-n> type x
```

Hmm, how can I teach to Power Shell about python3 is using
UTF-8 for stdout?
It seems cmd.exe with chcp 65001 and PYTHONUTF8=1 is better
than PowerShell when I want to use UTF-8 on Windows.

Anyway, nothing is wrong about python.  I just didn't understand
PowerShell at all.
History
Date User Action Args
2019-06-14 23:22:05methanesetrecipients: + methane, paul.moore, vstinner, tim.golden, zach.ware, eryksun, steve.dower
2019-06-14 23:22:05methanelinkissue37275 messages
2019-06-14 23:22:04methanecreate