端口是Erlang与外部程序通信的一种方式。
下图展现了端口与外部程序交互的方式。
OTP 常用的接口函数:
1、 打开端口
open_port/2
2、 通过端口,向外部程序发送数据
port_command
3、 通过端口,从外部程序接收数据
recieve
end.
4、 关闭端口
port_close/0
"Write an Erlang Port using OTP Principles" 这篇文章,详细讲解了如何通过OTP来编写一个端口应用,并通过这个应用来与外部的程序通信。
http://www.trapexit.org/Writing_an_Erlang_Port_using_OTP_Principles
代码在这里: http://www.kazmier.com/computer/port-howto.tar.gz