Question

defmodule MyModule do
   def print do
        IO.puts "hi all"
    end
end

This is my Elixir module contained in MyModule.erl

iex MyModule.erl
MyModule.print

I was trying to run the elixir method using a shell script. It compiles the file but

iex MyModule.erl

is not running. I think it's because the first command goes to Erlang virtual machine. How to call this method?

Was it helpful?

Solution

Elixir files generally have .ex extension. And if you are not planning to compile it, we recommend using the .exs file. We cover those differences in our getting started guide.

Assuming you write the file above to "mod.exs", one of the ways to achieve what you want is:

elixir -r mod.exs -e "MyModule.print"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top