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

Robert Raschke <>
Thu Jul 16 14:31:52 CEST 2015

When you call application:start(myapp) then the corresponding application
tuple from the .app file for that application is consulted to find which
module contains the startup code. This is the line with the 'mod' key. This
specifies the module and the arguments to pass as a second parameter to
that module's start/2 function as {Mod, StartArg}.

The reason for this is that when you are working in a (semi)interactive
environment, you would simply call the start function directly. And this
usually happens during development or testing. But when you have a finished
system, you have automated startup using the application framework. In this
case any arguments must be available via configuration. Thus you can
provide the arguments as part of the application configuration in the .app
file. There you can have an entry {mod, {myapp, some_erlang_term}} and this
would invoke myapp:start(normal, some_erlang_term).

I have not seen this used very often.

Hope this explains it a little bit,

On 13 July 2015 at 11:39, Nuku Ameyibor <> wrote:

> 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 <>
> 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
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150716/951574f0/attachment.html>

More information about the erlang-questions mailing list