How to know when a user redirects output from an erlang shell to a file

I have an example module

    -module (helloworld).
    -compile (export_all).

    main () -> io: format ("~ s ~ s ~ s ~ n", ["\ e [31m", "Hello world!", "\ e [0m"]).

When I create:

erlc helloworld.erl

After that I run:

erl -noshell -s helloworld main -s init stop
Hello world! (with red color)
 
erl -noshell -s helloworld main -s init stop> text.txt
^ [[31mHello world! ^ [[0m (The content in text.txt is ugly, so I don't like).

My problem:

  • How do I know when a user redirects output from an erlang shell to a file?
  • How can I write text.txt contents only "Hello world!" not "^ [[31mHello world! ^ [[0m"

Thank.

+3
3

http://www.erlang.org/doc/man/init.html#get_arguments-0, "noshell" , .

[{root,["/opt/local/lib/erlang"]},{progname,["erl"]},{home,["/Users/..."]},{noshell,[]}]]},{helloworld,main,0},{init,start_it,1},{init,start_em,1}]

0

io:rows/0, {ok, Number}, {error, enotsup}, . .

0

Thanks, but I don’t think this can solve my problem. I use isatty in the C library and solved it.

-2
source

Source: https://habr.com/ru/post/1751139/


All Articles