This is NOT a duplicate. The error is similiar, but the code is completly different and unrelated. There is no way I could use the answers from the other questions to solve this problem. There is no answer to this question on stackoverflow yet.
output = os.popen("dir").read()
'charmap' codec can't decode byte 0x88 in position 260: character maps to <undefined>
os.popen is just a wrapper around
subprocess.Popen along with a
The returned file object reads or writes text strings rather than bytes.
If Python's default encoding doesn't work for you, you should use
The underlying issue is that cmd writes ansi garbage by default, even when the output is to a pipe. This behavior may depend on your Windows version.
You can fix this by passing
/U flag to cmd:
p = subprocess.Popen('cmd /u /c dir', stdout=subprocess.PIPE) result = p.communicate() text = result.decode('u16')