in nodejs I run
var os = require("os")
os.hostname()
How can I get in elixir?
There doesn't seem to be a function in Elixir's standard library for this but Erlang has inet:gethostname/0
which you can call directly:
iex(1)> {:ok, hostname} = :inet.gethostname
{:ok, 'dogbert'}
iex(2)> hostname
'dogbert'
Just for sake of completeness you can also do this:
{hostname, exit_status} = System.cmd "hostname", [""]
{"TR01PPL010698\r\n", 0}
This works on Windows, *nix and Mac. As you can see it returns an Elixir binary (as opposed to an Erlang charlist) but you also may need to concern yourself with stripping away line-endings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With