zpeters
I feel like i’m missing something really basic here but for the life of me cannot figure this out.
When i run System.cmd(“echo”, [“hello”]). I get the output i expect, namely {“hello\n”, 0}
However when i run System.cmd(“lynx”, [“–dump”, “http://google.com”]) I get something like this
{<<10, 32, 32, 32, 83, 101, 97, 114, 99, 104, 32, 91, 49, 93, 73, 109, 97, 103,
101, 115, 32, 91, 50, 93, 77, 97, 112, 115, 32, 91, 51, 93, 80, 108, 97, 121,
32, 91, 52, 93, 89, 111, 117, 84, 117, 98, 101, 32, 91, …>>, 0}
When i run lynx --dump http://google.com from a shell it appears to be a normal string that is output. I don’t understand why running this command in elixir gives me a binary result.
If this is unavoidable, is there a way to convert from this binary to a string?
Thank you in advance for the schooling! ![]()
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
axelson
A String in Elixir is actually a UTF-8 encoded binary: https://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html
So both of your results are binaries. One way to verify/play with this is to run
From there you can see the raw “binary” representation is
<<104, 101, 108, 108, 111, 10>>and if you enter that into an iEX prompt you get back the string “hello\n” (note: this only works for binaries that are valid UTF-8 and all the characters are printable)So for some reason lynx is returning invalid UTF-8 when run as
lynx --dump http://google.com. To strip invalid characters you could do some processing like so: