Erlang: Command line to run a function in an Erl file

I can run the Erlang file either through the command line or bash script:

exec erl file.erl 

But I can’t figure out how to directly run the function inside this file.

eg.

 exec erl file.erl -f function() 

Any suggestions appreciated ...

+6
command-line bash erlang
source share
1 answer

what you probably want is erl -s module_name function_name

Note that you will never specify the erlang file in the erl command, as it was in your example. Erlang VM loads all modules into encoding. This includes the local directory.

From http://www.erlang.org/doc/man/erl.html :

-run Mod [Func [Arg1, Arg2, ...]] (init flag) Makes the init call the specified function. Initial Func settings. If there are no arguments, the function is considered arity 0. Otherwise, it is assumed that it is 1 by taking the list [Arg1, Arg2, ...] as an argument. All arguments are passed as strings. See Init (3).

-s Mod [Func [Arg1, Arg2, ...]] (init flag) Makes the init call the specified function. Initial Func settings. If there are no arguments, the function is considered arity 0. Otherwise, it is assumed that it is 1 by taking the list [Arg1, Arg2, ...] as an argument. All arguments are passed as atoms. See Init (3).

+13
source share

All Articles