0
启动应用程序时,返回值必须是pid或错误。对仅运行一次的程序使用elixir应用程序
是否可以使用应用程序来运行一次只能运行一次的程序。就像是。
defmodule MyApp do
use Application
def start(_type, _args) do
# Do stuff
{:done, :normal}
end
end
启动应用程序时,返回值必须是pid或错误。对仅运行一次的程序使用elixir应用程序
是否可以使用应用程序来运行一次只能运行一次的程序。就像是。
defmodule MyApp do
use Application
def start(_type, _args) do
# Do stuff
{:done, :normal}
end
end
你过于复杂@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
一个简单的脚本。
你可以找到更多关于这里的操作系统交互:http://elixir-lang.org/docs/stable/elixir/System.html#content,你可以看到多一点就到这里药剂脚本的话题:http://elixir-lang.org/getting-started/introduction.html#running-scripts
的应用程序是需要是稳健的长期运行程序...如果这是一次性的,例如一个控制台脚本,为什么不把它建模为一个脚本(.exs?)。如果它是强大的,为什么应用程序模型会给你带来麻烦? – bottlenecked
为什么你需要一个OTP应用程序呢? – mudasobwa
所以答案是不使用应用程序,并做出评论?我不确定是什么使得一个正确的混音项目。也许问题是混合项目对于单个运行程序来说是什么样子。 –