Thanks for posting the solution. Using `rebar escriptize` you can also configure the generated archive in a number of ways:<div><br></div><div>- escript_incl_apps lists applications whose beam files should also be bundled into the archive</div>
<div>- escript_shebang adds a custom shebang to the generated escript/archive</div><div>- escript_emu_args allows you to pass custom emulator arguments to the generated escript/archive<br><br>Cheers<br><br><div class="gmail_quote">
On 19 October 2011 09:16, Angel J. Alvarez Miguel <span dir="ltr"><<a href="mailto:clist@uah.es">clist@uah.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
as nobody care about this question, i post this just for newbies like me.<br>
<br>
I ended using rebar...<br>
<br>
i created a .src rebar file for my setup.<br>
<br>
walker.app.src<br>
<br>
{application, walker,<br>
[<br>
{description, ""},<br>
{vsn, "1"},<br>
{registered, []},<br>
{applications, [<br>
kernel,<br>
stdlib<br>
]},<br>
{mod, { walker, []}},<br>
{env, []}<br>
]}.<br>
<br>
and then having my walker.erl and the getopt.erl filesin my src directory<br>
<br>
i did "rebar compile" and then "rebar escriptize", rebar cares of generating a walker.app file<br>
and then packages all the beam files and the app making a fresh escript file.<br>
<br>
So you have to make a app file to allow escript manage the zip file..<br>
<br>
This is the result app file:<br>
<br>
<br>
{application,walker,<br>
[{description,[]},<br>
{vsn,"1"},<br>
{registered,[]},<br>
{applications,[kernel,stdlib]},<br>
{mod,{walker,[]}},<br>
{env,[]},<br>
{modules,[getopt,walker]}]}.<br>
<br>
Just for the record the walker.erl (a rip of ex1.erl from getopt) is :<br>
<br>
-module(walker).<br>
<br>
-export([main/1]).<br>
<br>
%% as of getopt examples<br>
option_spec_list() -><br>
CurrentUser = case os:getenv("USER") of<br>
false -> "user";<br>
User -> User<br>
end,<br>
[<br>
{recursion, $r, "recurse", {boolean,false}, "Recurse over directory contents"},<br>
{directory, undefined, undefined, string, "Target directory"}<br>
].<br>
<br>
main([]) -><br>
getopt:usage(option_spec_list(), escript:script_name());<br>
main(Args) -><br>
OptSpecList = option_spec_list(),<br>
io:format("Args (~p) ~ngetopt:parse/2 returns:~n~n", [Args]),<br>
case getopt:parse(OptSpecList, Args) of<br>
{ok, {Options, NonOptArgs}} -><br>
io:format("Options:~n ~p~n~nNon-option arguments:~n ~p~n", [Options, NonOptArgs]),<br>
case proplists:is_defined(directory,Options) of<br>
true -> do_walk(Options);<br>
false -> getopt:usage(OptSpecList, escript:script_name()) %% No target directory?<br>
end;<br>
{error, {Reason, Data}} -><br>
io:format("Error: ~s ~p~n~n", [Reason, Data]),<br>
getopt:usage(OptSpecList, escript:script_name())<br>
end.<br>
<br>
do_walk(Args) -><br>
Files = filelib:fold_files(proplists:get_value(directory,Args),<br>
".*",<br>
proplists:get_bool(recursion,Args),<br>
fun(Path, Acc) -><br>
io:format("Procesando fichero ~s \n",[Path]),<br>
{ok, Bin} = file:read_file(Path),<br>
[{Path, Bin}|Acc] end,<br>
[]).<br>
<br>
<br>
(A simple escript exercise for un cmdline tool that im planning to do)<br>
<br>
<br>
/Angel<br>
<br>
On Martes, 18 de Octubre de 2011 10:47:31 Angel J. Alvarez Miguel escribió:<br>
> Hi,<br>
><br>
> I want to packe some beams on a .ez archive and then insert the escript<br>
> header to get a selfcontaines script ala rebar..<br>
><br>
> i made a script witth a zip archive the usual way..<br>
><br>
> Files = filelib:fold_files("./ebin",<br>
> ".*",<br>
> true,<br>
> fun(Path, Acc) -><br>
> io:format("Procesando fichero ~s \n",[Path]),<br>
> {ok, Bin} = file:read_file(Path),<br>
> [{Path, Bin}|Acc] end,<br>
> []),<br>
> {ok, {"mem", ZipBin}} = zip:create("mem", Files, [memory]),<br>
> Script = <<"#!/usr/bin/env escript\n%%! -noshell -noinput\n",<br>
> ZipBin/binary>>,<br>
><br>
> ok = file:write_file("walker", Script),<br>
> os:cmd("chmod u+x walker"),<br>
><br>
><br>
> i have my ebin dir with my two test files, the getopt.erl from jcomellas<br>
> git and a simple walker.erl file:<br>
><br>
> -module(walker).<br>
><br>
> -export([main/1]).<br>
><br>
> main([String]) -><br>
> io:format("Up and running!! mayormente... (args:~s )\n",[String]),<br>
> halt(0);<br>
><br>
> main(_) -><br>
> io:format("Uso: ~s <args> \n",[escript:script_name()]),<br>
> halt(1).<br>
><br>
><br>
> but then escript doesnt find the walker file:<br>
><br>
> ./walker<br>
> escript: exception error: undefined function walker:main/1<br>
> in function escript:run/2<br>
> in call from escript:start/1<br>
> in call from init:start_it/1<br>
> in call from init:start_em/1<br>
><br>
> if I place the escript into the ebin files it obviouosly find the waker<br>
> module but is the .beam that is there!.<br>
><br>
><br>
> Do need I to include a "walker.app" to allow script to find where my main<br>
> function is from the zip archive?<br>
><br>
><br>
> Regards, Angel<br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>