[erlang-questions] badsig on sending message to the cat process

Joel Fernandes agnel.joel@REDACTED
Mon Feb 2 14:54:40 CET 2009


Hi,
I have been doing a little experiment with interfacing an erlang
process to one that accepts standard input and outputs to standard
output.
I chose the unix "cat" for this. The process starts and waits for
input when I do an open_port however it errors out with a message "**
exited: badsig **" when I try to send it some input.

The following is the program:

--module(cat).
-export([start/0]).

start() ->
        Port = open_port({spawn, "cat"}, [stream]),
        spawn(fun() -> loop(Port) end).

loop(Port) ->
        receive
                {call, Msg} ->
                        Port ! { self(), { command, Msg } },
                        receive
                                {Port, {data, Data}} ->
                                        io:format("received ~p~n", [Data]),
                                        loop(Port)
                        end;
                {'EXIT', Port, Reason} ->
                        exit(Reason)
        end.


and the shell session..

2> P = cat:start().
<0.34.0>
3> P ! {call, {data, "hello"}}.
{call,{data,"hello"}}** exited: badsig **

Any idea on why this could be happening?

Thanks for any help,
Joel



More information about the erlang-questions mailing list