Search code examples
elixirelixir-iex

Another way to exiting IEX other than ctrl-C


I know we can exit the IEX console with control-C. I'm curious if there's a command to type into the console that would also do the same thing.


Solution

  • I can think of 3 ways to quit an IEx shell:

    1. The mentioned <ctrl-c> hit twice or once followed by q and then <enter>,
    2. <ctrl-g> and then q + <enter>,
    3. and finally System.halt,

    but there is a difference between System.halt and the others.

    Namely that System.halt "halts the Erlang runtime" and the others just "quit the shell".

    When you have only one shell session running or the session is not attached to a separate runtime then both ways will produce the same result. But if you have a session connected to a separate runtime e.g. via iex --remsh (remote shell) then running System.halt in it will halt the runtime and so make both shell processes / runtimes terminate. Just quitting a shell (via method 1. or 2.) will not stop the runtime it is connected to.

    Conclusion: if you connect with your shell to other runtimes then know that System.halt will halt the runtime you have connected to. If you do not want to do it use other methods.

    UPDATE: Recently I have also found out about <ctrl-\>. You can read more about it in this article:

    What I didn’t know is that you can exit the shell by sending Ctrl-. The shell will exit immediately. As far as I know, it has the same effect as aborting the shell in the Break command, it doesn’t affect remote nodes and it also works outside of iex (for example, you can use to terminate your tests).