In Ruby, I would use the RUBY_PLATFORM constant to determine what operating system (Mac, Windows, Linux etc) my program is running on. Does Elixir have a way to get this information?
I'm currently attempting to re-create a Ruby program I wrote in Elixir, and I have a method that will make an OS-dependent system call to open a document. The method looks something like:
def self.open_document(filename)
case RUBY_PLATFORM
when %r(darwin)
system('open', filename)
when %r(linux)
system('xdg-open', filename)
when %r(windows)
system('cmd', '/c', "\"start #{filename}\"")
else
puts "Don't know how to open file"
end
end
I know I can run the Ruby Kernel.system commands using Elixir's System.cmd/3, but I'm not sure how to get the RUBY_PLATFORM value equivalent to make the switch on in the case statement, or whether I can actually get that information. Is this possible?
Update
As per Lol4t0's answer and for further reference:
iex> :os.type
{:unix, :darwin}
iex> System.cmd("uname", ["-s"])
{"Darwin\n", 0}