erlang入门之编译和运行

测试erlang脚本如下

-module(empty).
-author("mmc").

%% API
-export([test/1,test/0]).

test()->
  io:format("no arg~n").

test(X)->
  io:format("~p~n",[X]).

 

编译,一种是进入erl,然后

c(empty).

然后执行

empty:test().
empty:test(111).

 

还有一种命令行直接搞定

erlc empty.erl
或者
erlc +debug_info empty.erl
erl
-eval 'empty:test()' -noshell -s init stop erl -eval 'empty:test(12)' -noshell -s init stop

单引号换成双引号也可以,最后的init stop,自己去掉感受下就知道干什么用了

 

如果实现了application的接口(behavior),也可以用下面这个,后面的tcp_server不是模块名,而是rebar建立的工程里面的application的名字

erl -eval "application:start(tcp_server).

 

posted @ 2014-08-30 12:31  自由出土文物  阅读(301)  评论(0编辑  收藏  举报