Req #72896 [Opn]: Add a way to determine if output is redirected
| From: | mlocati at gmail dot com | Date: | Fri, 19 Aug 2016 08:28:47 +0000 |
| Subject: | Req #72896 [Opn]: Add a way to determine if output is redirected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203394@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
User updated by: mlocati at gmail dot com
Reported by: mlocati at gmail dot com
-Summary: Add a way if output is redirected
+Summary: Add a way to determine if output is redirected
Status: Open
Type: Feature/Change Request
Package: Output Control
Operating System: Windows
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
(Fixed the title of this bug report)
Previous Comments:
------------------------------------------------------------------------
[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