How to change a C-Node written with ei to be a port program?
erlang@REDACTED
erlang@REDACTED
Thu Mar 11 19:03:52 CET 2004
Hi,
thank you very much for this, works like charm so far.
> Set the port in binary mode and with a packet format of 3:
>
> open_port({spawn, "myprogram"}, [binary, {packet, 3}])
I had to set {packet, 4}. With a packet length size of 3, I get a badarg in open_port/2.
> When you send/receive through it, use term_to_binary and binary_to_term
> in Erlang:
>
> port_send(Port, term_to_binary(Message)),
>
> receive
> {Port, {data, Data}} ->
> Message = binary_to_term(Data)
> end
I take it you meant port_command/2 to send something to the port.
One question that I wasn't sure of: Should I be choosing the
port_command/2 and port_close/1 functions over the direct message
sending? The manual definitely suggests using the port_...
functions, so I'm going with that for now.
I also have problems with recognising the demise of the port program.
If I start it using the exit_status option, I get correct notification
if I kill the program from the outside, but not if I do an exit(1)
inside it (it's an unstable program ;). Not a big deal though.
A big thanks to the Erlang community for providing such great relief
to an otherwise drab progamming existence :-)
Robby
More information about the erlang-questions
mailing list