Reputation: 55
I want to pass arguments to a supervisor while I start an application like
mix run project.exs arg1 arg2
Now I don't know how to start an application with a script(exs) file which will start my supervisor (with those arguments)
I know about
escript: [main_module: App]
in mix.exs, provide def main(args): and then:
mix escript.build
./app
but it doesn't help me
I am totally new to elixir, any help would be appreciated.
Upvotes: 0
Views: 1584
Reputation: 11
you can use System.argv()
example:
def fun(n) do
--code
end
n= System.argv()
Upvotes: 0
Reputation: 2922
Typically arguments are passed to an application by means of environment variables[1].
You can then start your application by setting them in the commandline as such:
ARG1=value ARG2=value mix run project.exs
In your code you can then fetch them by means of
iex> System.get_env("ARG1")
value
[1] https://hexdocs.pm/elixir/System.html#get_env/2
Upvotes: 1