[issue14192] stdout.encoding not set when redirecting windows command line output

Redoute report at bugs.python.org
Sun Mar 4 10:42:34 CET 2012


New submission from Redoute <redoute at tortenboxer.de>:

When running a python script from windows command line (cmd.exe) and redirecting its output, stdout.encoding is set to None and printing non-ascii chars fails. Encoding should be the same as without redirecting.
Example:

[Code unictest.py]
# -*- coding: utf-8 -*-

from sys import stdout, stderr
print >> stderr, 'stdout.encoding: ', stdout.encoding
print u'äöüß'
[/Code]

[windows command prompt]
C:\Daten>testunic.py
stdout.encoding:  cp850
äöüß

C:\Daten>testunic.py > testunic.txt
stdout.encoding:  None
Traceback (most recent call last):
  File "C:\Daten\Cmd\testunic.py", line 5, in <module>
    print u'├ñ├Â├╝├ƒ'
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordin
al not in range(128)
[/windows command prompt]

----------
components: Windows
messages: 154885
nosy: Redoute
priority: normal
severity: normal
status: open
title: stdout.encoding not set when redirecting windows command line output
type: behavior
versions: Python 2.7

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


More information about the Python-bugs-list mailing list