I wrote a php script. I want it show help message when called with standard input connected to a tty device (terminal) before reading and executing interactively, but dont show
Since PHP 7.2 you can use stream_isatty, which works on Windows too.
For example:
php -r "var_dump(stream_isatty(STDERR));"
Results in
bool(true)
But
php -r "var_dump(stream_isatty(STDERR));" 2>output.txt
bool(false)
(this of course works on STDOUT too).