[erlang-questions] run escript with parameters passed via os cmd line
Andy Gross
andy@REDACTED
Thu Feb 28 04:05:24 CET 2008
From the escript docs ( http://erlang.org/doc/man/escript.html ) :
"""
An Erlang script file must always contain the function main/1. When
the script is run, the main/1 will be called with a list of strings
representing the arguments given to the script (not changed or
interpreted in any way).
"""
You probably want to turn your main/3 function into main/1, which
takes a *list* of arguments, as follows:
main([Node, Module, Args]) ->
.... code ....
- Andy
On Feb 27, 2008, at 9:57 PM, db wrote:
> How do you run escript with parameters?
>
> [db@REDACTED scripts]$ ./rpc_test nonode@REDACTED erlang_test test
> usage: You need to provide valid Node Name & Module Name & Args
>
> [db@REDACTED scripts]$ ./rpc_test main nonode@REDACTED erlang_test
> test
> usage: You need to provide valid Node Name & Module Name & Args
>
> Here is my escript called rpc_test:
>
> #!/usr/bin/env escript
> %% -*- erlang -*-
> %-mode(compile).
>
> -export([main/3, main/1, main/2]).
> %-export([main/3]).
>
> main(Node,Module,Args) ->
> try
> rpc:call(Node, Module, main, Args)
>
> catch
> _:_ ->
> usage1()
> end.
>
> main(_) ->
> usage().
>
> main(_,_) ->
> usage().
>
> usage() ->
> io:format("usage: You need to provide valid Node Name & Module
> Name & Args\n"),
> halt(1).
>
> usage1() ->
> io:format("usage1: RPC Call Problem\n"),
> halt(1).
>
>
> --
> rk
>
> That which we persist in doing becomes easier for us to do; not that
> the nature of the thing itself is changed, but that our power to do
> is increased.
> -Ralph Waldo Emerson _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list