Question about ports & eof

Chris Pressey <>
Sat Jul 20 09:39:06 CEST 2002


Is there any way to send an eof to a port without closing it?

I want to call a program and give it some data on standard input.  The
problem is that it won't give me back any data on standard output until it
gets an eof.

Basically something like...

  -module(test).
  -export([start/0]).

  start() ->
    P = open_port({spawn, "tar -c -f - -I -"}, [stream, use_stdio, eof]),
    port_command(P, "foo\nbar\nbaz\n"),
    port_command(P, eof), % if only it were this simple
    loop(P).
  
  loop(P) ->
    receive
      {P, {data, Data}} ->
        io:fwrite("~p~n", [Data]),
        loop(P);
      {P, eof} ->
        port_close(P)
    end.

I guess I might have to resort to a tmpfile here...

-Chris



More information about the erlang-questions mailing list