Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run erlang application without terminal depending

I have erlang application: *.app file and some *.erl files. I compile all of them. In terminal i start erl and there application:start(my_application)., all ok, but if i closed terminal application close too. How can i run application without terminal depending?

Thank you.

like image 891
0xAX Avatar asked Mar 11 '11 05:03

0xAX


People also ask

How do I run an Erlang program?

On a Unix system you enter the command erl at the operating system prompt. This command starts the Erlang runtime system and the Erlang shell. On the Windows platform you normally start Erlang/OTP from the start menu. You can also enter the command erl or werl from a DOS box or Command box.

How do I exit Erlang shell?

Well if you're in the shell of the node you want to turn down, even if it's not receiving input, you can still press Ctrl-g (which takes you to JCL mode). Once there you can use the command q to quit the Erlang shell. This is similar in effect to erlang:halt(0).

What is Erlang application?

Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecoms, banking, e-commerce, computer telephony and instant messaging.


2 Answers

You likely want to use the -noshell option to erl. The syntax is

erl -noshell -s Module Function Arguments

So in your case, this might be

erl -noshell -s application start my_application

This should allow you (for example if you are on Unix/Linux) to start your application as a background process and leave it running.

One useful variation is to also call the stop/0 function of the init module so that the Erlang environment will stop when it has finished running your function. This comes in handy if you want to run a simple one-use function and pipe the output to some other process.

So, for example, to pipe to more you could do

erl -noshell -s mymodule myfunction -s init stop | more

Finally, you might also be able to use the escript command to run your Erlang code as scripts rather than compiled code if it makes sense for your situation.

Hope that helps.

like image 162
irritate Avatar answered Oct 19 '22 07:10

irritate


The proper way to handle this situation, is building a release containing your app and running the system as so called embedded one. This release is going to be completely independent (it will hold erts and all the libs like, kernel, std, mnesia etc.). On start, the new process will not be connected to shell process. It will be OS process, so you can attach to it with pipes. All script are included in OTP. Here is some info: http://www.erlang.org/doc/design_principles/release_structure.html It may seem to be complicated, but tools like rebar do everything for you.

like image 27
user425720 Avatar answered Oct 19 '22 06:10

user425720