Req #72896 [Opn->Fbk]: Add a way to determine if output is redirected
| From: | cmb@php.net | Date: | Mon, 27 Jan 2020 11:28:26 +0000 |
| Subject: | Req #72896 [Opn->Fbk]: Add a way to determine if output is redirected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225132@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72896&edit=1
ID: 72896
Updated by: cmb@php.net
Reported by: mlocati at gmail dot com
Summary: Add a way to determine if output is redirected
-Status: Open
+Status: Feedback
Type: Feature/Change Request
Package: Output Control
Operating System: Windows
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
I think one can use sapi_windows_vt100_support()[1] for that
purpose.
[1] <https://www.php.net/manual/en/function.sapi-windows-vt100-support.php>
Previous Comments:
------------------------------------------------------------------------
[2016-08-19 08:28:47] mlocati at gmail dot com
(Fixed the title of this bug report)
------------------------------------------------------------------------
[2016-08-19 08:26:07] mlocati at gmail dot com
Description:
------------
Strictly related to https://bugs.php.net/bug.php?id=72768
If we enable color support for Windows, scripts may want to know if the output is redirected to
file.
For instance, we may print colored text if the standard output is not redirected to file, but we may
want to avoid ANSI control sequences if the output is redirected to a file.
I wrote a sample C program that does this check: https://gist.github.com/mlocati/21a9233ac83f7d3d7837535bc109b3b7
For posix systems it's already possible by using the posix_isatty PHP function (see what's
doing Symfony for instance: https://github.com/symfony/symfony/blob/2909e4b04d04653286b8d63b19e11a40157497b5/src/Symfony/Component/Console/Output/StreamOutput.php#L101
)
Test script:
---------------
<?php
if (SomeWayToDetermineIfStdoutIsRedirectedToFile) {
echo "Plain text";
} else {
echo \033[101;93m Colored text \033[0m\n"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72896&edit=1