Reputation: 1079
I've found several questions about how to read from STDIN in Erlang, but each of them seems focused on reading one piece of data, or one line at at time.
If I'm piping data to my Erlang program, how can I read all of the data that's been piped to STDIN and then do something with it once the input buffer is flushed? My use case is parsing JSON.
Upvotes: 2
Views: 174
Reputation: 1079
This snippet seems to do the trick:
read_all_stdin() ->
read_all_stdin([]).
read_all_stdin(Acc) ->
case io:get_line("") of
eof -> lists:reverse(Acc);
Line -> read_all_stdin([Line|Acc])
end.
Upvotes: 0