简单总结如何启动一个Erlang程序

简介: 一个例子

一个例子

这是取自SPOJ (强烈推荐这个OnlineJudge,几乎支持任何编程语言,google之)的第一道题目的答案。从标准输入读入N行整数,遇到42就退出。

Why 42 ? 
the answer to life, the universe and everything!
-module(tested).
-export([main/0]).
main() ->
    case io:get_line("") of
        {error, Why} -> io:format(Why);
        "42\n" -> void;
        Data -> io:format("~s~n",[Data]), main()
    end.
%% your module MUST be named "tested"

第1种方式,在erlang的shell中交互式编译运行

max@max-gentoo ~/Study/GitLab/SPOJ $ erl
Erlang/OTP 17 [erts-6.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V6.1  (abort with ^G)
1> c(tested).
{ok,tested}
2> tested:main()
2>

第2种方式,在命令行的提示符中运行

erl -noshell -s tested main -s init stop

第3种方式,碉炸天的erlang一行(没有perl一行易用)

erl -eval 'io:format("Memory:~p~n",[erlang:memory(total)]).' -noshell -s init stop

第4种方式,escript脚本

#!/usr/bin/escript
main(_) ->
     io:format("Hello World~n").
相关文章
|
5月前
|
NoSQL Redis Windows
windows环境启动redis-server.exe出现闪退问题解决方案(亲测有效)
windows环境启动redis-server.exe出现闪退问题解决方案(亲测有效)
470 0
|
5月前
|
Python
python 使用 AppiumService 类启动appium server
python 使用 AppiumService 类启动appium server
110 0
|
Java Shell Linux
Linux系列——编写Shell脚本快速启动ZooKeeper集群
Linux系列——编写Shell脚本快速启动ZooKeeper集群
|
Java Linux
linux系統java后台启动,liunx杀死java进程,后台启动jar包
linux系統java后台启动,liunx杀死java进程,后台启动jar包
83 0