Laravel Live Japan

stream_isatty

(PHP 7 >= 7.2.0, PHP 8)

stream_isattyПроверяет, относится ли поток к терминальному устройству TTY

Описание

stream_isatty(resource $stream): bool

Функция определяет, относится ли поток stream к действительному устройству терминального типа. Это более переносимая версия posix_isatty(), поскольку она работает и в системах Windows.

Список параметров

stream

Возвращаемые значения

Функция возвращает true, если выполнилась успешно, или false, если возникла ошибка.

Примеры

Пример #1 Пример использования функции stream_isatty()

Команда определяет, перенаправлен ли стандартный поток вывода или стандартный поток ошибок в файл.

php -r "var_export(stream_isatty(STDERR));"

Вывод приведённого примера будет похож на:


true
php -r "var_export(stream_isatty(STDERR));" 2>output.txt

Вывод приведённого примера будет похож на:


false

Добавить

Примечания пользователей 1 note

up
0
frmphp at dyadic dot org
23 days ago
This function returns False (output is being redirected) regardless of the form of redirection. On Windows, both of these are redirected:
- php.exe script.php > outFle.txt
- php.exe script.php | Tee outFle.txt
In the second case, Tee causes the redirection to also echo to the console.

An edge usage is: in debugging a long-running script, output is wanted both in a file for later review and also in the console so it's visible in real time. But if the script alters its output based on this function, then in the second case it will produce output as if for redirection only, even though Tee enables console output.
To Top