A Python program writes ascii characters, Hungarian accented characters and EM DASH characters to the standard output simply using the print() function. If I redirect the output:
python test.py > out.txt
sometimes the outputfile is generated with Shift-JIS encoding. Without the redirection the output is always perfect.The redirected output is not always wrong, it depends somehow on the content. I am on Wondows. Why can this happen? How can I avoid this? The following has been tried and it did not always help:
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
I tried printing several texts, the EM DASH character seems to be one culprit but I am not sure.