PHP 8.5.0 RC 5 available for testing

stream_isatty

(PHP 7 >= 7.2.0, PHP 8)

stream_isattyVerifica se um fluxo é um TTY

Descrição

stream_isatty(resource $stream): bool

Determina se o fluxo stream se refere a um dispositivo tipo terminal válido. Esta é uma versão mais portável de posix_isatty(), já que também funciona no Windows.

Parâmetros

stream

O fluxo a ser verificado.

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Exemplos

Exemplo #1 Exemplo de stream_isatty()

Este comando pode ser usado para determinar se um fluxo de saída/erro padrão é redirecionado a um arquivo.

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

O exemplo acima produzirá algo semelhante a:


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

O exemplo acima produzirá algo semelhante a:


false

adicionar nota

Notas de Usuários 1 note

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