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开发者_JS百科 if i closed terminal application close too. How can i run application without terminal depending?
Thank you.
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.
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.
精彩评论