Minimal embedded Erland system

Torbjorn Tornkvist <>
Wed Sep 22 23:17:00 CEST 1999


> 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.



More information about the erlang-questions mailing list