[erlang-questions] Why application:start can not accept any args?

Lihe Wang wanglihe.programmer@REDACTED
Tue Jul 14 01:54:25 CEST 2015


Thank you Nuku. Yes it is a solution pass args to a application, but why
not pass args directly by application:start(mycode1, Arg1)? Why otp design
a api this way? And application behaviour's callback function start, it
needs Args. It is seems like that something forgotten or something wrong.
In application.erl or somewhere, it generate a atom 'normal' and blank list
[], then passes them to mycode1:start(Type, Args). Why?

2015-07-13 18:39 GMT+08:00 Nuku Ameyibor <nayibor@REDACTED>:

> u can add environmental variables for your application in  your .app file
> .
> there is a tuple with a key env which u can use to add environmental
> variables to your application which you can then access from your
> application
> eg .
> {application, test,
>  [{vsn, "1.0.0"},
>   {description, "testing"},
>   {modules, [test, test_sup,test_start]},
>   {applications, [stdlib, kernel, crypto]},
>   {registered, [test,test_sup]},
>   {mod, {test, []}},
>   {env,
> [
> {env1,b},
> {env2,a},
> {env3,c}
> ]
> }
>  ]}.
>
> you can access them like so
> {ok, Env} = application:get_env(env1), etc..
>
> there is also a set_env/3 ,set_env/4 which can be used to change
> environmental variables during run-time
>
>
> On Sun, Jul 12, 2015 at 1:19 PM, Lihe Wang <wanglihe.programmer@REDACTED>
> wrote:
>
>> Can any one give the explain about OTP? The application behaviour's call
>> back "start" need args, but when I want start my code as a real
>> application, I only can write "applicaion:start(mycode)", and can not pass
>> any args to mycode. Why otp design like this? When I want start a
>> application as background service from escript, for example:
>>
>> main([Arg1, Arg2, Arg3]) ->
>>     application:start(mycode1), %%with Arg1
>>     application:start(mycode2),  %%with Arg2
>>     workcode(Arg3). %%workcode (escript) will run as a daemon, and need
>> service supplied by mycode1 and mycode2.
>>
>> What is the right way to write these code?
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150714/729a2d01/attachment.htm>


More information about the erlang-questions mailing list