How to compile Erlang application into binary executable and run it?

Now I'm learning Erlang, and I have a question about how to work and test Erlang applications.

We have several types of starting and testing Erlang programs:

  • We can run the Erlang shell and test our function there.
  • We can compile some files with our Erlang code than create an .app file and then run the Erlang shell again and call application:start(AppName).

My question is: Can we make a binary executable from Erlang code, such as C code? How can I run programs without the Erlang shell so that I can run the program, enter some command, and then call the Erlang functions for this command?

For example, I have a module ( test.erl) with three functions:

foo1() -> ...

foo2() -> ...

foo3() -> ...

-a foo1, -b foo2 ..

+3
3

, . bash - escript /.

+4

:

1. Erlang

Erlang ( .erl), - BEAM (.beam ), Erlang (BEAM), . , , , Erlang OTP, .

A.

, foo, :

$ erl \
-pa path/to/foo \
-s foo \
-sname foo_node \
-setcookie foo_secret \
-noshell -noinput > /path/to/foo.log &
  • -pa
  • -s foo
  • -sname
  • -setcookie cookie
  • -noshell erlang
  • -noinput -

:

$ erl \
-sname stop_foo_node \
-setcookie foo_secret \
-eval 'rpc:call(foo, foo_node, stop, []), init:stop()' \
-noshell -noinput > /path/to/foo.log &
  • -eval

foo :

$ erl \
-sname debug_foo_node \
-setcookie foo_secret \
-rmesh foo_node
  • -rmesh node

make script . , script -boot. , , , , . boot script Erlang.

.

- reltool, . , boot script, .. reltool . Erlang/OTP, reltool:

├── deps
│   └── ibrowse
├── ebin
│   ├── foo.app
│   ├── foo_app.beam
│   └── foo_sup.beam
├── rebar.config
├── rel
│   ├── files
│   ├── foo
│   └── reltool.config
└── src
    ├── foo_app.erl
    ├── foo.app.src
    └── foo_sup.erl

Rebar, Erlang Erlang, . , .

2. Erlang

Erlang :

  • Eunit: OTP, , , .

  • CommonTest: OTP, , .

" " " ". Rebar rebar eunit rebar ct .

3.

init:get_argument/1, , :

$ erl -foo foo1 foo2 -bar bar1
1> init:get_argument(foo).
{ok,[["foo1","foo2"]]}
2> init:get_argument(bar).
{ok,[["bar1"]]}
+4

eunit, .

+1

Source: https://habr.com/ru/post/1773501/


All Articles