Hi everybody,
I'm currently trying to learn a little bit of Elixir and was wondering: Why are there problems with special characters when invoked by a Windows shell?
For example if I start iex.bat (the Windows equivalent to iex) and try to write "Hallö" to the console I get the following result.
iex(1)> IO.puts "Hallö"
** (UnicodeConversionError) invalid encoding starting at <<148, 34, 10>>
(elixir) lib/string.ex:1418: String.to_char_list/1
A similar (maybe related) problem occurs when starting a phoenix app and hitting response times faster than 1 millisecond:
[info] Sent 200 in 1000┬Ás
The μ sign gets translated to some gibberish letters
-----------
What have I looked at so far:
iex.bat has problems with special characters on Windows, iex.bat --werl has not:
If I start iex.bat and try to print the o-umlaut ö and the microsecond sign μ I get this:
iex.bat
Interactive Elixir (1.1.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> IO.puts "ö"
** (UnicodeConversionError) invalid encoding starting at <<148, 34, 10>>
(elixir) lib/string.ex:1418: String.to_char_list/1
iex(1)> IO.puts "μ"
** (UnicodeConversionError) invalid encoding starting at <<230, 34, 10>>
(elixir) lib/string.ex:1418: String.to_char_list/1
Because of the mention in
Elixir introduction I also tested
iex.bat --werl:
The werl.exe which opens, is capable of writing the both characters, but can't print the μ sign (see attached image). The difference is, the μ sign gets printed as black box on input and output, indicating a missing character sign in the font.
iex.bat --werl
Interactive Elixir (1.1.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> IO.puts "ö"
ö
:ok
iex(2)> IO.puts "μ"
μ
:ok
The problem is not limited to iex.bat but happens on apps as well (if invoked by Powershell or cmd):
I then created a Elixir app with the following function:
The result wasn't good as well.
iex.bat -S mix
iex(1)> MicroSecondTest.sayMicro
"╬╝"
Windows consoles are generally able to write the special character signs:
I assumed this is a console problem, but Powershell as well as the Windows cmd tool are able to write the corresponding values (at least as values for variables).
Powershell:
PS C:\Users\Torben> $test="μ"
PS C:\Users\Torben> $test
μ
cmd
C:\Users\Torben>set test="μ"
C:\Users\Torben>echo %test%
"μ"
The erl shell can show the special chars as well:
Eshell V7.2.1 (abort with ^G)
1> io:fwrite("ö").
öok
2> io:fwrite("μ").
µok
Summary:
All tools on Windows seem to be capable of working with the "μ" sign, yet String.to_char_list/1 throws errors (and Phoenix fails on writing the "μ" sign as well, but doesn't throw errors).
So has anyone an idea where and how to look further?