[erlang-questions] Cannot start my application inside an escript (shame on me, rebar or what?)

Angel J. Alvarez Miguel clist@REDACTED
Mon Apr 30 13:22:44 CEST 2012


Hi

We are developing a molecular dynamics simulator in erlang so we have create an app structure of dirs 
and compile and bundle everything with rebar...

/src
./src/script_utils
./src/script_utils/getopt.erl....
./src/nosehoover.app.src
./src/nosehoover_core.erl
./src/nosehoover.erl
./src/nosehoover_tools.erl
./src/nosehoover_loader_gaussian.erl
./src/nosehoover_main.erl
./src/sim_utils
./src/sim_utils/group_membership.erl...
./data
./data/METANO...
./test
./test/thermo_test.erl
./test/dynamics_test.erl....
./ebin
./ebin/atom_utils.beam
./ebin/group_membership.beam
./ebin/nosehoover_loader_gaussian.beam.....
./plugins
./plugins/rebar_qc.erl
./include
./include/nosehoover_options.hrl
./include/constants.hrl
./rebar.config
.

We currently hook all functionality into the main() function on nosehoover.erl that escripts calls and this runs fine.

Now we want to leave only cmdline args procesing to the main function and start a full blown erlang app
creating worker and supervisors so first we are trying to start a minimal application.

################### nosehoover.erl  (-compile(export_all))

main(Argumentos) ->
    ok                       = application:load(nosehoover),
    {ok,Version}             = application:get_key(nosehoover,vsn),
    {ok,Description}         = application:get_key(nosehoover,description),
    Programa                 = escript:script_name(),
 
   % print a welcome message..
    io:format("Erlang Nosehoover(~s): ~s\n\n\n",[Version,Description]),

   % look for cmdline specs exported by my modules
    OptionProviders          = module_tools:list_app_modules(nosehoover,exports,option_specs),

    io:format("[ COMMAND LINE PARSING STAGE ]\nOptions providers found: ~w\n",[OptionProviders]),

   % build a complete specs list for getopt
    {OptSpecList,OptFunList} = collect_option_providers(OptionProviders), 

    case parse_args(OptSpecList, Argumentos, OptFunList) of
    {ok, {Opciones, _OtrosArgs}} ->  % ok lets start the whole thing
	% try to start the application 
        ok = application:start(nosehover),  % <---------- THIS IS THE ERROR!!
	% current entry point as a plain script app
        nosehoover_core:main(Opciones);
    {help} ->
        getopt:usage(OptSpecList, Programa);
    {version} ->
        io:format("~s (v ~s)\n~s\n", [Programa,Version,Description]);
    {error, {invalid_option_arg, Data}} ->
        io:format("Error:\n\t Invalid option: ~p~n~n", [Data]),
        getopt:usage(OptSpecList, Programa);
    {error, {Reason, Data}} ->
        io:format("Error:\n\t~s ~p~n~n", [Reason, Data]),
        getopt:usage(OptSpecList, Programa)
    end.

start(Type,Args) ->
   % just something to see if appp controller tried to start us...
   io:format("Application started (~w) with args:~p",[Type,Args]),
   {ok,self()}.

####################

We use application controller to load the bundled nosehoover.app in order to ask for what 
modules the app has and thinks like this, and it seem it find the app file and can load our app description, but 
 whenever i try to start the application there is a error:

escript: exception error: no match of right hand side value 
                 {error,{"no such file or directory","nosehover.app"}}
  in function  nosehoover:main/1 (src/nosehoover.erl, line 103)
  in call from escript:run/2 (escript.erl, line 727)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_it/1 
  in call from init:start_em/1

Its seems app controller can locate the app file and we can interrogate about app properties , but then it is 
unable to use it just to start the application.

Have anyone tried this way of doing things (start as an escript, the load and start an app), is there some problem with the app controller
and zip bundled beams, or mybe escript zip files are no suitable for full erlangs apps? 

ZIP dir structure looks flat while is should retain the app form?


Thanks in advance....




-- 
->>----------------------------------------------------------------------------

 Angel J. Alvarez Miguel, Servicios Informáticos
 Edificio Torre de Control, Campus Externo UAH
 Alcalá de Henares 28806, Madrid    ** ESPAÑA **

-------------[taH pagh taHbe', DaH mu'tlheghvam vİqelnİS]--<<-



More information about the erlang-questions mailing list