0

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

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

defmodule MyApp do
  use Application

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

1 回答 1

1

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

defmodule MyApp do
  def my_test_func do
    IO.puts "Hello world!"
  end
end

MyApp.my_test_func

将该代码另存为test1.exs. 然后你可以通过命令提示符运行它elixir test1.exs 我所说的是你不需要gen_server一个简单的脚本。

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

于 2016-10-03T13:22:29.570 回答