我怎样才能用 Elixir 制作一个没有多余输出的单文件脚本?

How can I make a single-file script with Elixir, without excess output?

我想做一些看起来应该很简单的事情,即制作一个只输出问候语的脚本。该脚本非常简单,不需要多个文件。这是我尝试过的:

[ ~/elixir ] cat hello.exs
#!/usr/bin/env iex
IO.puts "Hello world!"
:init.stop

[ ~/elixir ] ./hello.exs
Erlang/OTP 17 [erts-6.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Hello world!
Interactive Elixir (1.0.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> [ ~/elixir ]

这非常接近预期的结果,但我正在寻找类似 --quiet 或 --silent 标志的东西来抑制 Erlang 和 Elixir 启动消息。将 -S 标志添加到 iex 没有帮助:

[ ~/elixir ] cat hello.exs
#!/usr/bin/env iex -S
IO.puts "Hello world!"
:init.stop

[ ~/elixir ] ./hello.exs
Erlang/OTP 17 [erts-6.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

-S : Could not find executable ./hello.exs

我知道可以 (http://goo.gl/MtFTQF) 使用 mix 为此创建一个项目,但这似乎有些矫枉过正。我现在只想做一个简单的 hello 脚本。

您应该对 运行 Elixir 文件 (#!/usr/bin/env elixir) 使用 elixir 可执行文件。 iex 将执行文件并启动交互式 Shell。