When python opens stdin
and stdout
, it detects what encoding to use and uses text I/O to give you unicode strings.
But subprocess
does not (and can not) detect the encoding of the subprocess you start, so it'll return bytes. You can use a io.TextIOWrapper()
instance to wrap the child.stdout
pipe to provide unicode data:
sys.stdin = io.TextIOWrapper(child.stdout, encoding='utf8')