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

Jachym Holecek freza@REDACTED
Mon Feb 2 15:25:04 CET 2009


Hello,

# Joel Fernandes 2009-02-02:
> "** exited: badsig **" when I try to send it some input.

This means (see erlang:port_command/2):

  "If Port is open and the calling process is not the port owner,
   the port owner fails with badsig. The port owner fails with
   badsig also if Data is not a valid  IO list."

> The following is the program:
> 
> --module(cat).
> -export([start/0]).
> 
> start() ->
>         Port = open_port({spawn, "cat"}, [stream]),
>         spawn(fun() -> loop(Port) end).

The port owner is the process that called this function (shell),
but you're sending commands from a freshly spawned process. This
seems to be badsig #1.

> 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"}}.
                ^^^^^^^^^^^^^^^
This term isn't iodata(), yet it ends up being the `Msg' in
`{command, Msg}'. This seems to be badsig #2.

HTH,
	-- Jachym



More information about the erlang-questions mailing list