[erlang-questions] Treating data from open_port as an io_device()

Tom Werner pubsub@REDACTED
Mon Jun 30 22:07:42 CEST 2008


Can anyone recommend a way to treat the output from an open_port call as an
io_device() instead of as chunks of data that are delivered to the port's
controlling process and fetched via receive?

What I want is to use file:read/2 to read from the external process. The
reason is that data going TO the process already has 4 byte length headers
on it, so I can't use {packet, 4}. The data coming FROM the process also has
the headers so I'll need to do length header management myself which is
difficult (and inefficient) when dealing with chunked data.

Alternatively, is there a way to just create an in-memory io_device() that I
can use as a fifo? Then I could write the chunked data to the fifo and read
off the other side. I tried using a posix fifo file but file:open/2 will not
open it because of {error,eisdir}. It looks like I can open the fifo as a
port but that leaves me with the same exact problem.

I've looked all over the docs and asked in #erlang but I've seen no way to
create a simple pipe that I can use for this purpose!

Tom Preston-Werner
github.com/mojombo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080630/beeafba4/attachment.htm>


More information about the erlang-questions mailing list