elixir - 如何通过命令行参数来混合运行 --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"]
推荐阅读
- sql-server - 如何将数据从一台 SQL 服务器上的数据库复制到另一台 SQL 服务器上的数据库?
- c# - 在 C# 中将 SSRS 报告渲染为横向格式的 PDF
- c++ - 如何在opengl中平滑多个四边形的纹理
- google-maps - 如何使用 turfjs 在多边形内正确添加方形网格?
- python - 如何保存整个图表而不被切断?
- java - 如何处理 JPA 注释 @ManytoMany
- java - 如何将java类字段转换为字符串值数组
- c++ - 如何比在 C++ 中使用 qsort 更快地对一百万个数字进行分组?
- hadoop - 如何从hadoop将数据导出到大型机
- c# - 将数据从数据库拖到列表框