string.decode() throws an error, when i try to decode the line output of an stdout.PIPE. The error message is:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x84 in position 8: invalid start byte
0x84 should be the letter 'ä'. The line that fails reads as follows:
b' Datentr\x84ger in Laufwerk C: ist System'
I can't nail it down. I already checked the encoding using sys.stdout.encoding, which is utf-8.
import subprocess
import re
prc = subprocess.Popen(["cmd.exe"], shell = False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
prc.stdin.write(b"dir\n")
outp, inp = prc.communicate()
regex = re.compile(r"^.*(\d\d:\d\d).*$")
for line in outp.splitlines():
match = regex.match(line.decode('utf-8'))# <--- decode fails here.
if match:
print(match.groups())
prc.stdin.close()