Using python 3, running the following code
print("some box drawing:")
print("┌─┬┼┴┐")
via
py my_app.py
prints
some box drawing:
┌─┬┼┴┐
As you would expect.
However, if you redirect this (either Windows or Linux) with
py my_app.py > redirected.txt
you get the following exception:
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-5: character maps to <undefined>
As has been suggested in many other posts, this exception can be "fixed" by calling sys.stdout.reconfigure(encoding='utf-8')
prior to printing. On linux and in the windows cmd, thats it, problem solved. Using PowerShell on Windows however, the output looks like this:
some box drawing:
ΓöîΓöÇΓö¼Γö╝Γö┤ΓöÉ
Which is especially odd, since it works fine using the cmd.exe console.
The code base is delivered to a customer as an executable and I would like to not ask them to execute something in the console in order for my program to work reliably. Is there a programmatic way to have box drawing characters written correctly when redirecting output to a file using the windows PowerShell?