Message345646
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. |
|
Date |
User |
Action |
Args |
2019-06-14 23:22:05 | methane | set | recipients:
+ methane, paul.moore, vstinner, tim.golden, zach.ware, eryksun, steve.dower |
2019-06-14 23:22:05 | methane | link | issue37275 messages |
2019-06-14 23:22:04 | methane | create | |
|