Tuesday 19 November 2013

Input from the standard input

Can you read the standard input stream in an escript?

Yes you can but the obvious script to copy a file:

main([]) ->
    copyLoop().

copyLoop() ->
    case io:get_chars("", 1) of
C ->
       io:put_chars(C),
       copyLoop();
eof ->
       ok
    end.

This does read and write, but does not halt when it gets to the end of a file that you pipe in.  Hmm.  I'm doing plenty of file reading but I'll open the files in code.

No comments:

Post a Comment