ITeye博客

Erlang学习: 通过端口与外部程序通信

rstevens · 2012-08-16 00:02 · 编程语言:Erlang · 编程语言 · Erlang · port · otp · Markdown

端口是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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。