| Author |
Message |
|
| jfk at informaticon.dk |
Posted: Wed Sep 22, 1999 7:39 pm |
|
|
|
Guest
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> I have tried to make a minimal embedded Erlang system to use as a template. However, when i start the system - even in embedded mode - I get an Erlang shell prompt.
The files involved are:
test.erl:
======
-module(test).
-behaviour(application).
-export([hello_sayer/0, start/2, stop/1]).
hello_sayer() ->
|
|
|
| Back to top |
|
| tobbe at serc.rmit.edu.au |
Posted: Wed Sep 22, 1999 9:17 pm |
|
|
|
Guest
|
> I have tried to make a minimal embedded Erlang system to use as a
> template. However, when i start the system - even in embedded mode - I
> get an Erlang shell prompt.
Try out the following program (included below).
Cheers /Tobbe
-module(pipe).
%%% ====================================================================
%%% Example how to use Erlang in a series of Unix pipes
%%% ---------------------------------------------------
%%% First create a file with some in data:
%%%
%%% cat > indata
%%% 1 2 3 4 5
%%% 5 4 3 2 1
%%% ^D (NB: Control-D)
%%%
%%% Then run the following:
%%%
%%% erl -s pipe -noinput < indata | tee outdata
%%% 1 2 3 4 5
%%% 5 4 3 2 1
%%%
%%% (Also, inspect the created file: cat outdata )
%%% ====================================================================
-export([start/0]).
-export([init/0]).
start() ->
spawn(?MODULE,init,[]).
init() ->
Port = open_port({fd, 0, 1},[eof]),
loop(Port).
loop(Port) ->
receive
{Port, {data, What}} ->
Port ! {self(), {command, What}},
loop(Port);
{Port, eof} ->
halt()
end.
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| klacke at bluetail.com |
Posted: Thu Sep 23, 1999 7:23 am |
|
|
|
Guest
|
> I make a boot script using systools:make_script() and start the system
> using "erl -boot test -mode embedded -pz /home/jfk/test/ebin". The
If you replace the "-mode embedded " with -noshell, the shell isn't
started. (Also note that the erlc compiler knows how to compile
.rel files, we can just call erlc test.rel to produce the script+boot
files.)
An even easier way to make a small script to run your erlang code is
erl -noshell -s test
> shell, write something to standard output and then exit to the Unix
io:format(... writes to stdout, halt() exits the erlang system back
to the unix shell.
There is no _easy_ way to write to stderr.
/klacke
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| etxuwig at etxb.ericsson. |
Posted: Thu Sep 23, 1999 8:20 am |
|
|
|
Guest
|
On Wed, 22 Sep 1999, Joergen Froejk Kjaersgaard wrote:
jfk>I have tried to make a minimal embedded Erlang system to use as a
jfk>template. However, when i start the system - even in embedded mode
jfk>- I get an Erlang shell prompt.
The '-mode embedded' is a misnomer. What it means is that the erlang system
will preload all the modules instead of loading on demand.
/Uffe
Ulf Wiger, Chief Designer AXD 301 <ulf.wiger_at_etx.ericsson.se>
Ericsson Telecom AB tfn: +46 8 719 81 95
Varuv |
|
|
| Back to top |
|
| joe at bluetail.com |
Posted: Thu Sep 23, 1999 9:08 am |
|
|
|
Guest
|
On Wed, 22 Sep 1999, Joergen Froejk Kjaersgaard wrote:
> I have tried to make a minimal embedded Erlang system to use as a
> template. However, when i start the system - even in embedded mode - I
> get an Erlang shell prompt.
>
... Ummm :-)
> test.erl:
> ======
> -module(test).
> -behaviour(application).
> -export([hello_sayer/0, start/2, stop/1]).
>
> hello_sayer() ->
> io:put_chars("hello, world
"),
> receive _ -> []
> end.
... Minimal! - the very fact that you call "io:" means you have to pull in a
dozen or so modules and it won't be very minimal!
... cut ...
> test.app:
> =======
> {application, test,
> [{description, "A simple test application"},
... etc ...
Using applications is the wrong way to go if you are making
miminimal systems.
To find out how to do this read section 1.4 of "System principles"
very carefully.
It's at
http://www.erlang.org/doc/doc/doc/system_principles/system_principles.html#1.4
You will need to pre-load exactly two modules to make a minimal system
init.erl and erl_prim_loader.erl
In
http://www.erlang.org/examples/examples-2.0.html
under the section sos you will find a description of a complete mini
OS which can you simple io - using sos instead of io you can write:
-module(sos_test1).
-export([main/0]).
main() ->
sos:write("Hello world
").
To run this we must first compile sos_test1
using the compiler in the Erlang development environment. Once we have done
this then we can run the program as follows:
unix> sos sos_test1
Hello world
We can time this as follows:
> time sos sos_test1
Hello world
0.09u 0.04s 0:00.37 35.1
The details are in http://www.erlang.org/examples/examples-2.0.html
Actually sos.erl is worthly of study since it *is* an entire applocation
OS in a few hundred lines.
/Joe
--
Joe Armstrong,
Bluetail AB, tel: +46 8 692 22 11
Hantverkargatan 78, fax: +46 8 654 70 71
SE-112 38 Stockholm, Sweden info: www.bluetail.com
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| joe at bluetail.com |
Posted: Thu Sep 23, 1999 9:15 am |
|
|
|
Guest
|
On Thu, 23 Sep 1999, Klacke wrote:
>
>
>
> > I make a boot script using systools:make_script() and start the system
> > using "erl -boot test -mode embedded -pz /home/jfk/test/ebin". The
>
> If you replace the "-mode embedded " with -noshell, the shell isn't
> started. (Also note that the erlc compiler knows how to compile
> .rel files, we can just call erlc test.rel to produce the script+boot
> files.)
>
> An even easier way to make a small script to run your erlang code is
> erl -noshell -s test
>
> > shell, write something to standard output and then exit to the Unix
>
> io:format(... writes to stdout, halt() exits the erlang system back
> to the unix shell.
>
> There is no _easy_ way to write to stderr.
>
>
> /klacke
If you want to make a minimal system you should not use io but
hit the IO file descriptors *directly* here is cat.erl
which does this:
main(_) ->
Port = erlang:open_port_prim({fd,0,1}, [eof, binary]),
loop(Port).
loop(Port) ->
case read(Port) of
eof ->
true;
{ok, X} ->
write(Port, [X]),
loop(Port)
end.
read(Port) ->
receive
{Port, {data, Bytes}} ->
{ok, Bytes};
{Port, eof} ->
eof
end.
write(Port, X) ->
Port ! {self(), {command, X}}.
If the next release of OSE contains the shared library
and tiny application builder
code stuff then this will compile to a 872 byte executable.
<<is this in the next release Bj |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|