问题描述
我想在启动像这样的应用程序时将参数传递给主管
I want to pass arguments to a supervisor while I start an application like
mix run project.exs arg1 arg2
现在我不知道如何使用脚本文件(exs)启动应用程序,从而启动我的主管(带有这些参数)
Now I don't know how to start an application with a script(exs) file which will start my supervisor (with those arguments)
我知道
escript: [main_module: App]
,提供def main(args):然后提供:
in mix.exs, provide def main(args): and then:
mix escript.build
./app
但是对我没有帮助
我对长生不老药来说是全新的,任何帮助将不胜感激。
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
在您的代码中, n然后通过
In your code you can then fetch them by means of
iex> System.get_env("ARG1")
value
[1]
这篇关于如何从命令行将参数传递给主管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!