2014-01-14 9 views
2

얼랭 코드에 두 개의 인수를 전달해야합니다. Erlang 쉘에서 잘 작동합니다.얼랭 명령 줄

2> crop:fall_velocity(x,23). 
    21.23205124334434 

하지만 얼랭 (Erlang) 셸 없이는 얼랭 코드를 어떻게 실행해야합니까? 일반 파이썬처럼, C 프로그램. ./program_name ($ 1 $ 2 인수를 전달하지 않음).

나는이

erl -noshell -s crop fall_velocity(x,20) -s init stop 

을 시도하고 있었다 그러나 예기치 않은 토큰 오류를주고있다.

답변

5

-s 하나만 원자 목록 -run로서 공급 모든 파라미터가 동일 않고 문자열 목록으로 전달한다. 임의의 매개 변수 개수와 유형으로 임의의 함수를 호출하려면 -eval을 사용해야합니다.

$ erl -noshell -eval 'io:format("test\n",[]),init:stop()' 
test 
$ 
4

escript을 사용하면 Erlang 스크립트를 명령 줄에서 실행할 수 있습니다. 이 스크립트에서는 인수 배열을 문자열로 사용하는 main 함수를 만들어야합니다.

#!/usr/bin/env escript 

main(Args) -> 
    io:format("Printing arguments:~n"), 
    lists:foreach(fun(Arg) -> io:format("Got argument: ~p~n", [Arg]) end,Args). 

출력 :

documentation states로서
./escripter.erl hi what is your name 5 6 7 9 
Printing arguments: 
Got argument: "hi" 
Got argument: "what" 
Got argument: "is" 
Got argument: "your" 
Got argument: "name" 
Got argument: "5" 
Got argument: "6" 
Got argument: "7" 
Got argument: "9"