Sepehr Samini
Sepehr Samini

Reputation: 1045

How run a function with parameter in a module from linux command line

I have a function start with two parameters in module mymodule. How can I run this function from command line.

I try this:

erl -name [email protected] -s mymodule start 5 10

But It raises error: {"init terminating in do_boot",{undef,[{mymodule,start,[['5','10']]},{init,start_it,1},{init,start_em,1}]}}

I want to be able to run this function from a bash file

Upvotes: 0

Views: 526

Answers (1)

Jr0
Jr0

Reputation: 2173

I think it expects the start function to have arity of one, so in this case it is attempting to call module:start(['5','10']). So change your start function to accept a list of 2 parameters as in [arg1,arg2]. Also, check out the documentation on the -run and -s flags. -s passes arguments as atoms while -run passes them as strings

-run Mod [Func [Arg1, Arg2, ...]](init flag) Makes init call the specified function. Func defaults to start. If no arguments are provided, the function is assumed to be of arity 0. Otherwise it is assumed to be of arity 1, taking the list [Arg1,Arg2,...] as argument. All arguments are passed as strings. See init(3).

Upvotes: 3

Related Questions