[erlang-questions] How can I close standard input output streams and check for errors in Erlang?

Steven Stewart-Gallus <>
Fri Jan 3 22:02:44 CET 2014


Hello Erlang-Questions!

I checked on another forum previously at
http://www.reddit.com/r/erlang/comments/1txf60/how_can_one_flush_and_close_standard_streams_in/
and at the Erlang IRC channel on Freenode but I couldn't get help so
I've come to the mailing list. Can Erlang-Questions help me figure out
how to close standard input output streams and check for errors in
Erlang? I should be able to report an error if standard input and
output don't close properly and return an exit code of 1 if closing
standard error doesn't work.

My problem:

> A simple hello world program is
> 
> -module(hello).
> -author('').
> -export([hello_world/0]).
> 
> hello_world() -> io:fwrite("hello, world~n")
> 
> I can compile and run this with erl -compile hello && erl -noshell -s
> hello hello_world -s init stop and it works. But what if I run it as
> erl -compile hello && erl -noshell -s hello hello_world -s init stop >
> /dev/full (on a Linux box)? That doesn't work correctly (correct
> behaviour should be reporting a full hard disk). *I know in C and Java
> I can close standard streams to flush them and check for errors but
> how can I do so in Erlang?
> 
> *Strictly speaking one can't write this program correctly in portable
>  C or Java either because operating system kernels like Linux defer
>  writes so one has to do an fsync call for absolute correctness.

Thank you,
Steven Stewart-Gallus



More information about the erlang-questions mailing list