[erlang-questions] Issues with stdin on ports

Richard A. O'Keefe ok@REDACTED
Tue Jul 30 08:23:59 CEST 2013

On 30/07/2013, at 6:02 PM, Anthony Grimes wrote:
> I'm simply asking how I'm supposed to deal with programs that I have *no* control over that wait for a EOF on their input to start producing data. I just want to send a ^D.

End of file and Control-D are two different things.
UNIX technically doesn't have a character that signifies end of file.
There is an "EOF" character, but what it does is "send the current line NOW",
and sending a line with *no* characters, not even a newline, causes a read()
to return 0, and _that_ is the end of file indication.
Since 1979, when I started using UNIX, my end-of-file character has been
Control-Z, to be compatible with the other computer systems I was using.
I am rather fed up with readline-infested programs that insist on Control-D
instead of accepting the EOF character I set up.

And a program that waits for all of its input before producing any data
is by definition not a filter.

There is a very very simple technique.
(1) Create a temporary file.
(2) Create a pipe, telling that pipe to write to the temporary file.
(3) Send your data to the pipe and close the pipe.
(4) Now read the temporary file.

I still don't understand why you can't do this/

> I have examples of programs that do that and a thousand ways to do it in other languages, and I'm being told it is disastrous to do. If the solution is to just keep doing what everybody has been doing in Erlang for years which is write giant hack middleman programs to do it,

No, that is NOT what everybody has been doing in Erlang.
Creating a temporary file is simple and safe and easy to program.

More information about the erlang-questions mailing list