How can I pass arguments to supervisor from command line

我怕爱的太早我们不能终老 提交于 2019-12-11 15:59:14

问题


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.


回答1:


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




回答2:


you can use System.argv()

example:

 def fun(n) do
      --code
     end

    n= System.argv()


来源:https://stackoverflow.com/questions/57734459/how-can-i-pass-arguments-to-supervisor-from-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!