Message345551
When stdout is redirected to file and cp65001 is used, stdout encoding is unexpectable:
# Power Shell 6 (use cp65001 by default)
PS C:¥> python3 -c "print('おはよう')" > ps.txt
# cmd.exe
C:¥> chcp 65001
C:¥> python3 -c "print('おはよう')" > cmd.txt
Now, ps.txt is encoded by UTF-8, but cmd.txt is encoded by cp932 (ACP).
This is because:
* TextIOWrapper tries `os.device_encoding(1)`
* `os.device_encoding(1)` use GetConsoleOutputCP() without checking stdout is console
In the example above, a console is attached when python is called from Power Shell 6, but it is not attached when python is called from cmd.exe.
I think using GetConsoleOutputCP() for non console is abusing.
---
There is a relating issue: UTF-8 mode doesn't override stdin,stdout,stderr encoding when console is attached.
On Unix, os.device_encoding() uses locale encoding and UTF-8 mode overrides locale encoding. Good.
But on Windows, os.device_encoding() uses GetConsole(Output)CP(). UTF-8 mode doesn't override it.
If we stop abusing GetConsoleOutputCP(), this issue is fixed automatically.
But if we keep using GetConsoleOutputCP() for stdout which is not a console, UTF-8 mode should override it. |
|
Date |
User |
Action |
Args |
2019-06-14 05:46:30 | methane | set | recipients:
+ methane, paul.moore, vstinner, tim.golden, zach.ware, steve.dower |
2019-06-14 05:46:30 | methane | set | messageid: <1560491190.29.0.949105060129.issue37275@roundup.psfhosted.org> |
2019-06-14 05:46:30 | methane | link | issue37275 messages |
2019-06-14 05:46:29 | methane | create | |
|