所以我有一个遵循以下布局的应用程序模块:
defmodule Project.Application do
use Application
def start(_type, _args) do
children = [
randomchild1,
randomchild2,
{Project.runapp, "argument" }
]
opts = [strategy: :one_for_all, name: Project.Supervisor]
Supervisor.start_link(children, opts)
end
end
现在当我运行它时,我使用mix run --no-halt
并且它运行完美。
我想用我在命令行中传递的值替换"参数"?我不知道如何向mix run --no-halt
添加参数.
我想做的只是将一个值传递给 start 方法并使用它来定义子进程。
>mix
自愿重置System.argv/1
。--no-halt
选项是运行应用程序的临时方式;通常,我们用mix release
组装版本,并使用ebin/my_app start
正常启动它们。
当您仍然想求助于mix run --no-halt
时,创建空文件(mix
将尝试在启动时执行它(,并调用类似mix
mix run --no-halt -- "empty.exs" 42
现在,在您的Application.start/2
中,您可以与System.argv/0
进行争论
def start(_type, args) do
IO.inspect(System.argv())
...
检查一下。
mix run --no-halt -- "empty.exs" 42
#⇒ ["422"]