archimondain
Dealing with :os.cmd with unicode characters
For some reason the following does not work in elixir:
:os.cmd("echo toto")
instead I read somewhere that this should be done
:os.cmd(to_charlist "echo toto")
which gives the expected result:
"toto\n"
but if now one wants to use non ascii character, like with this :
:os.cmd(to_charlist "echo à")
then the result becomes
[224, 10]
The question is : how can I have "à\n" as a result ?
Marked As Solved
sribe
You probably already do. But I’m guessing your source is not UTF, but rather some common Windows page, and 224 is the character you’re looking for. Because 10 is “\n”. When a char list is all ASCII chars it is displayed as a string, otherwise it is displayed as a list of byte values.
And the reason the first form does not work is that many older erlang commands only take char lists, not binaries. BTW, ‘echo toto’ would work just as well, as long as you’re using constants. (Of course if you have a binary arg passed in, then you’ll need that to_charlist call.)
Also Liked
archimondain
Indeed, that was silly of me to think otherwise. I had an encoding issu that I had a hard time to solve and I was investigating all the possibilities. It turned out that Docker was causing the problem.
Thanks
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









