[erlang-questions] erlang port and C executable

Joe Williams <>
Sat Nov 22 00:37:59 CET 2008


Hello,

I am having an issue when I attempt to send and receive messages to a C 
executable. I believe the task should be fairly trivial but I am getting 
hung up on sending messages to the port. Here's what I have so far:

> Eshell V5.6.3  (abort with ^G)
> 1> Cmd = "SOME_EXECUTABLE",
> 1> Port = open_port({spawn, Cmd}, []).
> #Port<0.93>
> 2> receive
> 2> {Port, {data, Data}} ->
> 2> io:format("~p~n", [Data]);
> 2> Error ->
> 2> io:format("~p~n", [Error])
> 2> end.
> "TEXT FROM THE EXECUTABLE"
> ok
> 3> Port ! <<"TEXT TO THE EXECUTABLE">>.
> ** exception exit: badsig
> 4> Port ! <<"TEXT TO THE EXECUTABLE">>.
> <<"TEXT TO THE EXECUTABLE">>
> 5> receive                                     
> 5> {Port, {data, Data}} ->
> 5> io:format("~p~n", [Data]);
> 5> Error ->
> 5> io:format("~p~n", [Error])
> 5> end.

After the last end my code just hangs and waits to receive a message 
rather than receiving the response from "TEXT TO THE EXECUTABLE". Since 
it received the first message properly I assume it would receive further 
responses in the same way. So I have two questions, the first is what 
does "exception exit: badsig" generally mean? The second how can I write 
this in such a way that I can send and receive strings until I have the 
program exit?

Any guidance is appreciated.

-Joe

-- 
Name: Joseph A. Williams
Email: 




More information about the erlang-questions mailing list