I'm making a shell out of Python.
import os
from subprocess import check_output
print(check_output("dir", shell=True).decode('utf-8'))
It is a program that returns and prints the returned value when you enter the cmd command using the subprocess module.
It works well if you enter a command with only English return values, but if you use a command mixed with Korean, for example, the dir command, UnicodeDecodeError occurs.
The error name is as follows
'utf-8' codec can't decode byte 0xb5 in position 3: invalid start byte
If the return value is mixed with byte and utf-8 like this, how should I decode it? ㅠ<
python decoding unicodedecodeerror
It's not a byte problem, but it's using euc-kr when encoding Korean in Windows (unlike other os).
Fix it like the bottom.
print(check_output("dir", shell=True).decode('euc-kr'))
© 2025 OneMinuteCode. All rights reserved.