Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch a control-c to the Erlang shell?

Tags:

erlang

I am running a gen_server and I want to do some cleanup before it exits. When I run this from the command line, I'm given an Erlang shell prompt. I have a handle_info({'EXIT'}, From, Reason}, and a terminate(Reason, State) in the gen_server function definitions. When I control-c in the Erlang shell, neither of these seem to be triggered.

So, how can I catch the control-c entered at the Erlang shell, in my gen_server?

Edit: I've been pressing control-c to get the menu, then control-c again to break out of the shell.

like image 748
Turtle V. Rabbit Avatar asked Sep 26 '22 06:09

Turtle V. Rabbit


1 Answers

Do you mean that you press CTRL-C and then (a)bort? CTRL-C itself is intercepted by Shell to show you the menu. However, when you press abort it stops the Erlang VM unconditionally. You would need to quit the shell gracefully, .e.g. with q(). or init:stop().

like image 149
Greg Avatar answered Oct 11 '22 16:10

Greg