将elixir应用程序用于仅运行一次的程序

时间:2016-10-03 09:32:39

标签: elixir otp mix

启动应用程序时,返回值必须是pid或错误。

是否可以将应用程序用于仅运行一次处理的程序。像。的东西。

defmodule MyApp do
  use Application

  def start(_type, _args) do
    # Do stuff
    {:done, :normal}
  end
end

1 个答案:

答案 0 :(得分:1)

你过度复杂的事情@Peter。你想要的是一个Elixir脚本(exs文件)。从这个例子开始:

@Override
public Object postProcessBeforeInitialization(Object o, String string) throws BeansException {
    System.out.println("---before initialization ------ " + o..getClass().getName());
    return o;
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

将该代码保存为defmodule MyApp do def my_test_func do IO.puts "Hello world!" end end MyApp.my_test_func 。然后,您可以通过test1.exs从命令提示符运行它。我说的是,您不需要elixir test1.exs来创建一个简单的脚本。

您可以在此处找到有关与操作系统交互的更多信息:http://elixir-lang.org/docs/stable/elixir/System.html#content,您可以在此处查看有关Elixir脚本主题的更多信息:http://elixir-lang.org/getting-started/introduction.html#running-scripts