[issue21927] BOM appears in stdin when using Powershell

Jason R. Coombs report at bugs.python.org
Fri Jul 11 18:15:06 CEST 2014


Jason R. Coombs added the comment:

I get different results that @haypo when testing Powershell on Windows 8.1 with Python 3.4.1:

C:\Users\jaraco> chcp 1252
Active code page: 1252
C:\Users\jaraco> $env:PYTHONIOENCODING=''
> How you do change the console encoding? Using the chcp command?

Yes. I recently discovered that if I use chcp 65001 in my Powershell profile, I can finally see Unicode characters output from my Python programs!

> I'm surprised that you get a UTF-8 BOM when the code page 1252 is used. Can you please check that sys.stdin.encoding is "cp1252"?

C:\Users\jaraco> echo foo | python -c "import sys; print(sys.stdin.readline())"
foo

C:\Users\jaraco> python -c "import sys; print(sys.stdin.encoding)"
cp1252

C:\Users\jaraco> chcp 65001

C:\Users\jaraco> echo foo | python -c "import locale, os; print(os.device_encoding(0), locale.getpreferredencoding(False))"
None cp1252

It seems as if something may have changed in Powershell between Windows 7 and 8.1, because my results are inconsistent with your findings.

There's a lot more to digest from your response, so I'll going to have to revisit this later.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21927>
_______________________________________


More information about the Python-bugs-list mailing list