All pastes #460052 Raw Edit

Stuff

public text v1 · immutable
#460052 ·published 2007-04-26 20:35 UTC
rendered paste body
-module(pipe).
-compile(export_all).

%%---------------------------------------------------
%% 1> erl -s pipe -nouser < indata | tee outdata
%% 1 2 3 4 5
%% 5 4 3 2 1
%% 5 1 2 3 4
%% 4 3 2 1 5
%%---------------------------------------------------

start() ->
    spawn(pipe,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.