Running an application from the (unix) command line

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Running an application from the (unix) command line

J. Pablo Fernández
Hello,
how do you run an application from the command line ?
erl -s application start myapp
doesn't seem to work.
Thanks.
--
Pupeno <[hidden email]> (http://pupeno.com)
Vendemos: Kit del guitarrista: http://pupeno.com/vendo/#kit

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

Matthias Lang
Pupeno writes:
 > Hello,
 > how do you run an application from the command line ?
 > erl -s application start myapp
 > doesn't seem to work.

Try following the instructions in the FAQ exactly:

  | 5.7. ...run an Erlang program directly from the unix shell?
  |
  | To run Erlang programs without running the Erlang shell, we just pass
  | some more switches to the Erlang virtual machine. Here's hello world
  | again:
  |
  | -module(hello).
  | -export([hello_world/0]).
  |
  | hello_world() ->
  | io:fwrite("hello, world\n").
  |
  |
  | Save this as hello.erl, compile it and run it directly from the unix
  | (or msdos) command line:
  |
  | matthias >erl -compile hello
  | matthias >erl -noshell -s hello hello_world -s init stop
  | hello, world
       
You find the rest of the FAQ at

  http://www.erlang.org/faq/t1.html

and if you want to know the full details of command line passing, this
part of the manual explains it:

  http://erlang.se/doc/doc-5.4.12/erts-5.4.12/doc/html/erl.html

Matthias
Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

J. Pablo Fernández
I've read the FAQ and the manual, that is how I know erl -s takes Module
[Fuction [Arguments]] and that is how I came up with
erl -s application start myapp
on the first place (which you cas nee I mention in my first mail), which
doesn't work.
Thanks.

On Saturday 21 January 2006 04:53, Matthias Lang wrote:

> Pupeno writes:
>  > Hello,
>  > how do you run an application from the command line ?
>  > erl -s application start myapp
>  > doesn't seem to work.
>
> Try following the instructions in the FAQ exactly:
>   | 5.7. ...run an Erlang program directly from the unix shell?
>   |
>   | To run Erlang programs without running the Erlang shell, we just pass
>   | some more switches to the Erlang virtual machine. Here's hello world
>   | again:
>   |
>   | -module(hello).
>   | -export([hello_world/0]).
>   |
>   | hello_world() ->
>   | io:fwrite("hello, world\n").
>   |
>   |
>   | Save this as hello.erl, compile it and run it directly from the unix
>   | (or msdos) command line:
>   |
>   | matthias >erl -compile hello
>   | matthias >erl -noshell -s hello hello_world -s init stop
>   | hello, world
>
> You find the rest of the FAQ at
>
>   http://www.erlang.org/faq/t1.html
>
> and if you want to know the full details of command line passing, this
> part of the manual explains it:
>
>   http://erlang.se/doc/doc-5.4.12/erts-5.4.12/doc/html/erl.html
>
> Matthias
--
Pupeno <[hidden email]> (http://pupeno.com)
Vendemos: Camara de fotos rusa ЗЕНИТ ET (ZENIT) con flash ФОТОН:
http://pupeno.com/vendo/#camara

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

Gunilla Arendt
In reply to this post by J. Pablo Fernández
Snip from erl(1):

"-s Mod [Func [Arg1, Arg2, ...]]
  Makes init call the specified function. Func defaults to start. If no
  arguments are provided, the function is assumed to be of arity 0.
  Otherwise it is assumed to be of arity 1, taking the list
  [Arg1,Arg2,...] as argument."

Thus "erl -s application start myapp" will result in a call to
"application:start([myapp])" instead of the desired
"application:start(myapp)".

I recommend you create a boot script which starts your application
instead. You can either write a .rel file and use it to generate
a boot script, or edit an existing .script file and use
systools:script2boot/1 to transform it into a .boot file. See
OTP Design Principles and systools(3) for details.

/ Gunilla

Pupeno wrote:
> Hello,
> how do you run an application from the command line ?
> erl -s application start myapp
> doesn't seem to work.
> Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

Bengt Kleberg
In reply to this post by Matthias Lang
On 2006-01-21 08:53, Matthias Lang wrote:
...deleted
> Try following the instructions in the FAQ exactly:
>
>   | 5.7. ...run an Erlang program directly from the unix shell?

...deleted
>   | matthias >erl -noshell -s hello hello_world -s init stop
>   | hello, world
 >
 > You find the rest of the FAQ at
 >
 >   http://www.erlang.org/faq/t1.html
 >

when i looked at the faq this was 5.6. did i get the wrong
(old/obsolete) faq?


moreover, i think that the faq should also mention that ''init stop''
will be run in parallell with ''hello hello_world''. this is important
when something longer running than hello_world is started this way :-)


bengt
Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

J. Pablo Fernández
In reply to this post by Gunilla Arendt
On Monday 23 January 2006 05:36, Gunilla Arendt wrote:

> Snip from erl(1):
>
> "-s Mod [Func [Arg1, Arg2, ...]]
>   Makes init call the specified function. Func defaults to start. If no
>   arguments are provided, the function is assumed to be of arity 0.
>   Otherwise it is assumed to be of arity 1, taking the list
>   [Arg1,Arg2,...] as argument."
>
> Thus "erl -s application start myapp" will result in a call to
> "application:start([myapp])" instead of the desired
> "application:start(myapp)".
This doesn't work, I don't know why but what I see is that my parameters get
totally ignored.

> I recommend you create a boot script which starts your application
> instead. You can either write a .rel file and use it to generate
> a boot script, or edit an existing .script file and use
> systools:script2boot/1 to transform it into a .boot file. See
> OTP Design Principles and systools(3) for details.

This is the route I am taking. Thank you. :)
--
Pupeno <[hidden email]> (http://pupeno.com)
Vendemos: Conocer y collecionar Monedas y Billetes de Todo el Mundo:
http://pupeno.com/vendo/#monedas

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

Thomas Johnsson
In reply to this post by Bengt Kleberg
Bengt Kleberg wrote:
...
moreover, i think that the faq should also mention that ''init stop'' will be run in parallell with ''hello hello_world''. this is important when something longer running than hello_world is started this way :-)
That appears not to be true: when I run
    erl -noshell shtest loop -s init stop
with
loop() ->
    io:format("loop...~n",[]),
    timer:sleep(1000),
    loop().
i
t just keeps writing ....

---------

While we are on this subject I'd like to add a few related questions:

1. How do I get rid of the "text junk output" written on standard out in the beginning of a run? Like:

Erlang (BEAM) emulator version 5.4.5 [hipe] [threads:0] [kernel-poll]

=PROGRESS REPORT==== 24-Jan-2006::09:07:13 ===
          supervisor: {local,sasl_safe_sup}
             started: [{pid,<0.32.0>},
                       {name,alarm_handler},
                       {mfa,{alarm_handler,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

(I don't get this with the Windows )

2. There appears to be quite a big start-up cost (or maybe it is termination cost),
> time erl -noshell -s init stop
may take about a second. Any suggestions in how to reduce this?

Any other suggestions on using erlang standalone as smoothly as possible will be greatly appreciated.

-- Thomas





Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

Thomas Johnsson
In reply to this post by J. Pablo Fernández
Pupeno wrote:
On Monday 23 January 2006 05:36, Gunilla Arendt wrote:
  
Snip from erl(1):

"-s Mod [Func [Arg1, Arg2, ...]]
  Makes init call the specified function. Func defaults to start. If no
  arguments are provided, the function is assumed to be of arity 0.
  Otherwise it is assumed to be of arity 1, taking the list
  [Arg1,Arg2,...] as argument."

Thus "erl -s application start myapp" will result in a call to
"application:start([myapp])" instead of the desired
"application:start(myapp)".
    

This doesn't work, I don't know why but what I see is that my parameters get 
totally ignored.
  
That's strange. With
-module(echo).
-export([echo/1]).
echo(A) ->
    io:format("~w~n",[A]).

and run with
erl -noshell -s echo echo abc 123 -s init stop
I get
[abc,'123']
written on standard out (plus some junk before that). This on Solaris. This works on windows too (without getting junk before).

What os are you using? Perhaps you are expecting to get the function value result written on standard out?

Hope this helps,
-- Thomas




Reply | Threaded
Open this post in threaded view
|

RE: Running an application from the (unix) command line

Ulf Wiger (TN/EAB)
In reply to this post by J. Pablo Fernández
 
Pupeno wrote:

> > Thus "erl -s application start myapp" will result in a call to
> > "application:start([myapp])" instead of the desired
> > "application:start(myapp)".
>
> This doesn't work, I don't know why but what I see is that my
> parameters get totally ignored.

It's because the application:start/1 function doesn't expect
the argument to be wrapped inside a list.

You can write your own function that does expect the wrapper,
and simply unwraps it. For example:

-module(myapp).

-export([start/1]).


start([App]) ->
   application:start(App).


Then use: erl ... -s myapp start App

/Uffe
Reply | Threaded
Open this post in threaded view
|

RE: Running an application from the (unix) command line

Vlad Dumitrescu XX (LN/EAB)
In reply to this post by J. Pablo Fernández
 Hi,
 
> 1. How do I get rid of the "text junk output" written on standard out in the beginning of a run? Like:
 > =PROGRESS REPORT==== 24-Jan-2006::09:07:13 ===
 >           supervisor: {local,sasl_safe_sup}
  >             started: [{pid,<0.32.0>},
   >                      {name,alarm_handler},
    >                     {mfa,{alarm_handler,start_link,[]}},
     >                    {restart_type,permanent},
      >                   {shutdown,2000},
       >                  {child_type,worker}]

 > (I don't get this with the Windows ) 
 
Could it be that the Solaris version uses a different boot script, possibly sasl.boot instead of the simple (and otherwise default) start.boot?
 
regards,
Vlad
 

Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

Bengt Kleberg
In reply to this post by Thomas Johnsson
On 2006-01-24 10:41, Thomas Johnsson wrote:

> Bengt Kleberg wrote:
>> ...
>> moreover, i think that the faq should also mention that ''init stop''
>> will be run in parallell with ''hello hello_world''. this is important
>> when something longer running than hello_world is started this way :-)
> That appears not to be true: when I run
>     erl -noshell shtest loop -s init stop
> with
> loop() ->
>     io:format("loop...~n",[]),
>     timer:sleep(1000),
>     loop().
> it just keeps writing ....

either i did a mistake when looking into the problem (most likely), when
i remember it, or this (fix?) has been introduced since 2002 (when i had
the problem).


> While we are on this subject I'd like to add a few related questions:
>
> 1. How do I get rid of the "text junk output" written on standard out in
> the beginning of a run? Like:
>
> Erlang (BEAM) emulator version 5.4.5 [hipe] [threads:0] [kernel-poll]
>
> =PROGRESS REPORT==== 24-Jan-2006::09:07:13 ===
>           supervisor: {local,sasl_safe_sup}
>              started: [{pid,<0.32.0>},
>                        {name,alarm_handler},
>                        {mfa,{alarm_handler,start_link,[]}},
>                        {restart_type,permanent},
>                        {shutdown,2000},
>                        {child_type,worker}]
>
> (I don't get this with the Windows )

try starting like this:
erl -sasl sasl_error_logger false ...


> 2. There appears to be quite a big start-up cost (or maybe it is
> termination cost),
>  > time erl -noshell -s init stop
> may take about a second. Any suggestions in how to reduce this?

Stand-alone Erlang (http://www.sics.se/~joe/sae.html).

also, somebody made a c-program that can load a module (and execute it)
into a running erlang system, from the unix command line. that was
faster than starting erlang.
i never used it, just read about it.


> Any other suggestions on using erlang standalone as smoothly as possible
> will be greatly appreciated.

i have a script called erl_run that i (hard) link to when i want to run
a new erlang module standalone.
it says:
#! /bin/sh

module=`basename $1`

erl +A 2 -sasl sasl_error_logger false -noshell -q -pa
/home/eleberg/private/erlang/ebin -pa
/home/eleberg/private/erlang/lib/erlang -s $module main $*


the idea is that all my standalone erlang modules are in
/home/eleberg/private/erlang/ebin and has a main/1 exported. so the
erlang module ''bepp'' has a /home/eleberg/private/erlang/ebin/bepp.beam
and a /home/eleberg/bin/bepp shell script. the latter is a link to erl_run.


bengt
Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

Mats Cronqvist
In reply to this post by Thomas Johnsson
   you could try this;

$ time erl -boot start_clean -noshell -s echo echo foo -s erlang halt
[foo]

real    0m0.226s
user    0m0.215s
sys     0m0.007s

   mats

Thomas Johnsson wrote:

> Pupeno wrote:
>
>> On Monday 23 January 2006 05:36, Gunilla Arendt wrote:
>>  
>>
>>> Snip from erl(1):
>>>
>>> "-s Mod [Func [Arg1, Arg2, ...]]
>>>  Makes init call the specified function. Func defaults to start. If no
>>>  arguments are provided, the function is assumed to be of arity 0.
>>>  Otherwise it is assumed to be of arity 1, taking the list
>>>  [Arg1,Arg2,...] as argument."
>>>
>>> Thus "erl -s application start myapp" will result in a call to
>>> "application:start([myapp])" instead of the desired
>>> "application:start(myapp)".
>>>  
>>
>>
>> This doesn't work, I don't know why but what I see is that my
>> parameters get totally ignored.
>>  
>>
> That's strange. With
> -module(echo).
> -export([echo/1]).
> echo(A) ->
>    io:format("~w~n",[A]).
> and run with
> erl -noshell -s echo echo abc 123 -s init stop
> I get
> [abc,'123']
> written on standard out (plus some junk before that). This on Solaris.
> This works on windows too (without getting junk before).
>
> What os are you using? Perhaps you are expecting to get the function
> value result written on standard out?
>
> Hope this helps,
> -- Thomas
>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Running an application from the (unix) command line

Gunilla Arendt-2
In reply to this post by Thomas Johnsson

> 1. How do I get rid of the "text junk output" written on standard out in
> the beginning of a run? Like:
>
> Erlang (BEAM) emulator version 5.4.5 [hipe] [threads:0] [kernel-poll]
>
> =PROGRESS REPORT==== 24-Jan-2006::09:07:13 ===
>           supervisor: {local,sasl_safe_sup}
>              started: [{pid,<0.32.0>},
>                        {name,alarm_handler},
>                        {mfa,{alarm_handler,start_link,[]}},
>                        {restart_type,permanent},
>                        {shutdown,2000},
>                        {child_type,worker}]
>
> (I don't get this with the Windows )

This is a SASL progress report, which probably means you are using
the start_sasl boot script. If this is not your intention, run
the Install script again and make sure to answer 'y' to the question
"Do you want to use a minimal system startup instead of the SASL
startup?". (See System Principles for more information).

If you do want to start the SASL application, but not get its progress
reports, this can be configured. (See SASL User's Guide). Example:

$ erl -boot start_sasl -sasl sasl_error_logger false

/ Gunilla
Reply | Threaded
Open this post in threaded view
|

RE: Running an application from the (unix) command line

Ulf Wiger (TN/EAB)
In reply to this post by J. Pablo Fernández
 
Try "erl ... -sasl errlog_type error"
 
 
 
/Uffe


From: [hidden email] [mailto:[hidden email]] On Behalf Of Vlad Dumitrescu XX (LN/EAB)
Sent: den 24 januari 2006 11:04
To: Thomas Johnsson
Cc: [hidden email]
Subject: RE: Running an application from the (unix) command line

 Hi,
 
> 1. How do I get rid of the "text junk output" written on standard out in the beginning of a run? Like:
 > =PROGRESS REPORT==== 24-Jan-2006::09:07:13 ===
 >           supervisor: {local,sasl_safe_sup}
  >             started: [{pid,<0.32.0>},
   >                      {name,alarm_handler},
    >                     {mfa,{alarm_handler,start_link,[]}},
     >                    {restart_type,permanent},
      >                   {shutdown,2000},
       >                  {child_type,worker}]

 > (I don't get this with the Windows ) 
 
Could it be that the Solaris version uses a different boot script, possibly sasl.boot instead of the simple (and otherwise default) start.boot?
 
regards,
Vlad