Minimal embedded Erland system

Joe Armstrong <>
Thu Sep 23 11:15:13 CEST 1999


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örn???>>

/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




More information about the erlang-questions mailing list