[erlang-questions] escript and ctrl+c

Erik Søe Sørensen eriksoe@REDACTED
Mon Apr 2 23:33:21 CEST 2012


Not quite.
I believe Dmitry misunderstood the question; this is not about how to 
make the escript program exit, but how to catch when a user makes it 
exit - presumably for some cleanup work.

Well, here's the bad news: it appears that the treatment of the SIGINT 
signal is rather hardcoded - to either making the Erlang VM shut down, 
or escaping to an options menu, depending on how Erlang was started.
(At least that's what I got out of looking at unix/sys.c, break.c, and 
erl_check_io.c.)

I suppose that given Erlang's server-side origins, enabling custom 
signal handling hasn't been a priority...

As for a solution, it probably depends a lot on what you're trying to 
accomplish.
The possibilities I see:
a) using sigaction() directly - probably not a good solution; hard to 
make thread-safe.
b) using NIFs to install a cleanup handler with at_exit().
c) writing a wrapper script which handles cleanup.
d) writing a wrapper script in bash or similar, for catching the signal 
and passing in to the escript in a suitable way.

/Erik


Den 02-04-2012 20:08, Vivek Ayer skrev:
> Hi Dmitry,
>
> So you're saying ctrl+c just throws some error code and I have to
> write a halt function that handles that? Basically, I just want do
> something similar to:
>
> try:
>
> except Exception:
>
> that you'd see in python.
>
> Thanks for the quick reply!
> Vivek
>
> On Mon, Apr 2, 2012 at 10:32 AM, Dmitry Kolesnikov<dev@REDACTED>  wrote:
>> Hello,
>>
>> erlang:halt(ErrorCode) make the trick for you.
>>
>> - Dmitry
>>
>> On Apr 2, 2012, at 8:23 PM, Vivek Ayer wrote:
>>
>>> Hi List,
>>>
>>> I've been using escripts to prototype erlang code. It's really great
>>> and you can have something functional (no pun intended) very quick,
>>> similar to prototyping in python.
>>>
>>> Anyways, escript serves all my needs except for shutdown signals. I
>>> can't quite figure out how make an exit action like 'Ctrl+C' trigger
>>> something like an 'exit' or 'stop' routine in my scripts. How would I
>>> go about accomplishing this? Help appreciated.
>>>
>>> Thanks,
>>> Vivek
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list