systools and scripts

Martin J. Logan mlogan@REDACTED
Fri May 7 17:57:42 CEST 2004


I wrote the following function that will apply any function from the
command line.


%%--------------------------------------------------------------------
%% @doc Allows any function to be called from the command line via erl
-s 
%% all arguments should be passed in the following manner:
%% erl -s mod func "arg1. " "arg2. "...
%% <pre>
%% Variables: 
%%  MFSList - a list containing the mod func and a list of args to apply
comming via erl -s
%%
%% Types:
%%  MFAList = [Mod, Func|Args] Example [file, list_dir, '"/var/log". ']
%%
%% Example Invocation:
%%  erl -pz ../ebin/ -s fs_lib s_apply io format "\"hello ~p\". "
"[world]. "
%%   
%% </pre>
%% @spec s_apply(MFAList) -> void()
%% @end 
%%--------------------------------------------------------------------
s_apply([Mod, Func|Args]) ->
    io:format("fs_lib:s_apply args before parsing: ~w~n", [Args]),
    TokedArgs = lists:map(fun(ArgAtom) ->
                                  {ok, Toks, Line} =
erl_scan:string(atom_to_list(ArgAtom), 1),
                                  {ok, Term}       =
erl_parse:parse_term(Toks), 
                                  Term
                          end, Args),
    io:format("apply the following: apply(~w, ~w, ~p)~n", [Mod, Func,
TokedArgs]),
    apply(Mod, Func, TokedArgs).


so to run this function from the command line for a function like 

io:format("hello ~p~n", [world]).

you would invoke 

erl -pz ../ebin/ -s fs_lib s_apply io format "\"hello ~p\". " 
"[world]. "

notice that all the arguments for the function that you want applied are
strings containing terms. The containing strings are terminated with a
.<space? see the docs for erl_scan and erl_parse for an explaination.
Make sure that you properly escape any of the terms contained by the
strings. 

Cheers,
Martin




On Thu, 2004-05-06 at 00:40, Dustin Sallings wrote:
> 	I'm trying to use a makefile to build my application, but I can't 
> figure out how to run systools from the erl commandline.  I want to run 
> the following command:
> 
> 	systools:make_script("environ", [local]).
> 
> 	...but I can't seem to express that.
> 
> 
> 	I've just added another module to my build system that creates the 
> .boot and the .tar.gz, but is this necessary?
> 
> --
> SPY                      My girlfriend asked me which one I like better.
> pub  1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin@REDACTED>
> |    Key fingerprint =  87 02 57 08 02 D0 DA D6  C8 0F 3E 65 51 98 D8 BE
> L_______________________ I hope the answer won't upset her. ____________




More information about the erlang-questions mailing list