[issue5290] subprocess.Popen.communicate does not encode unicode strings

Beda Kosata report at bugs.python.org
Tue Feb 17 09:25:44 CET 2009


New submission from Beda Kosata <beda at zirael.org>:

The method subprocess.Popen.communicate (more the underlying
_communicate) writes the input to the stdin stream without encoding,
regardless of it being a unicode string. The result is incorrect
behavior of the running program as it receives 4 bytes for each character.
As simple text program is here:

import subprocess
from base64 import b16encode

command = ["cat"]
p = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
data = u"test text"
o, er = p.communicate(data)
print b16encode(o)

I believe that this issue is closely related to Issue2683 where this was
fixed for Python 3.0.

----------
components: Library (Lib)
messages: 82304
nosy: beda
severity: normal
status: open
title: subprocess.Popen.communicate does not encode unicode strings
type: behavior
versions: Python 2.5

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


More information about the Python-bugs-list mailing list