toraritte / program

1 stars 0 forks source link

How to read from standard input in an escript? #2

Closed toraritte closed 5 years ago

toraritte commented 5 years ago

https://gist.github.com/afrantisak/d293e9dc173f229048f0 https://elixirforum.com/t/io-read-stdio-num-broken-in-1-2-6/2547 https://stackoverflow.com/questions/10872909/erlang-read-stdin-write-stdout

=> refresh memory on io and file modules io - http://erlang.org/doc/man/STDLIB_app.html file - http://erlang.org/doc/man/kernel_app.html

toraritte commented 5 years ago

https://learnyousomeerlang.com/functionally-solving-problems (search for file:) https://dynamicprogrammer.com/2012/10/11/the-file-module-part-2-learning-erlang-8/

toraritte commented 5 years ago
#!/usr/bin/env escript

% main(Args) -> 
%    io:format("~p~n", [length(Args)]).

main([]) ->
  io:format("~p~n", [[]]);
main(Args) ->
    io:format("~p~n", Args).

When invoked as

$ cat .gitignore | ./program

the single argument of main will be an empty list. (Check by inverting the comments above.)