erlang server on port 6657?

79 Views Asked by At

Problem : I am trying to run the noshell command as following and keep alive the server on port 6657, but seems that does not work.

run_server.sh

erl -make
erl -pa ebin/ -noshell -s server main 6657 -s init stop

Erlang module function

main(Port) ->
    controller:start(),

FYI, on erlang prompt I can execute command - server:main(6667) that works fine.

Can you please suggest me what I need to change in that command ?

Thanks you !

1

There are 1 best solutions below

5
Dogbert On

Assuming you have the module name right (you say server in the first snippet and chat_server later), the problem most likely is that -s module function arg1 [...] sends the arguments as a list of atoms, while your code requires a single integer (as you said server:main(6657) works). You can use -eval instead of -s:

erl -pa ebin/ -noshell -eval "server:main(6657)" -s init stop
$ cat a.erl
-module(a).
-compile(export_all).

main(Port) ->
  io:format("~p~n", [Port]).
$ erlc a.erl
$ erl -noshell -pa . -s a main 6657 -s init stop
['6657']
$ erl -noshell -pa . -eval 'a:main(6657)' -s init stop
6657