I need to know if the standard input of my escript is a terminal or not. io:getopts()
is almost there, except that it checks is the standard output is a tty or not.
$ cat x.escript
#!/usr/bin/env escript
main(_) ->
io:format("~p~n", [proplists:get_value(terminal, io:getopts(), unknown)]).
This is how it works:
$ ./x.escript # stdin and stdout are both ttys
true
$ echo | ./x.escript # stdin is not a tty, but stdout is
true
$ ./x.escript | cat # stdin is a tty, but stdout goes to a pipe => it is not a tty
false
This clearly checks the stdout. Is there a way to check if the stdin is a terminal?