Phillipp

Phillipp

System.stop(1) does not return code to shell

Hey,

I am developing an escript and want to return the code 1 to the shell in case of an error, so if my tool gets automated, the automation scripts can detect an error based on the returned code.

So, to keep it simply, we return right from the main function of my escript entrypoint module:

  def main(_args) do
    System.stop(1)
  end

Then after I run my generated escript:

$ echo $?
0

Am I right that there should be a 1 instead of a 0?

Most Liked

josevalim

josevalim

Creator of Elixir

Usually it is fine for escripts and sometimes even desired for faster shutdown. The difference is that System.halt() does not shutdown the applications supervision trees one by one. It just halts the system.

elbrujohalcon

elbrujohalcon

I tried with…

defmodule Excript.CLI do
  def main(args \\ []) do
    {opts, _, _} = OptionParser.parse(args, switches: [halt: :boolean])
    if opts[:halt], do: System.halt(1), else: System.stop(1)
  end
end

…and could definitely reproduce the error, see:

$ ./excript --halt
$ echo $?
1
$ ./excript
$ echo $?
0

As @Phillipp says… it’s an issue with erlang escripts.

Last Post!

OvermindDL1

OvermindDL1

You can always manually shut down parts that need to be shut down cleanly before calling it though (just don’t shut down the kernel before you get a chance to call halt). :slight_smile:

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement