如何传递命令行参数来混合运行 --no-halt



所以我有一个遵循以下布局的应用程序模块:

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"]    

最新更新