PHP 8.5.0 Released!

stream_isatty

(PHP 7 >= 7.2.0, PHP 8)

stream_isattyVerifica si un flujo es un TTY

Descripción

stream_isatty(resource $stream): bool

Determina si el flujo stream se refiere a un dispositivo de tipo terminal válido. Esta es una versión más portable de posix_isatty(), ya que también funciona en sistemas Windows.

Parámetros

stream

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Ejemplos

Ejemplo #1 Ejemplo con stream_isatty()

Este comando puede ser utilizado para determinar si un flujo de salida / error estándar es redirigido a un fichero.

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

Resultado del ejemplo anterior es similar a:


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

Resultado del ejemplo anterior es similar a:


false

add a note

User Contributed Notes 1 note

up
0
frmphp at dyadic dot org
11 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