Req #72896 [NEW]: Add a way if output is redirected
| From: | mlocati at gmail dot com | Date: | Fri, 19 Aug 2016 08:26:10 +0000 |
| Subject: | Req #72896 [NEW]: Add a way if output is redirected | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-203392@lists.php.net to get a copy of this message | ||
From: mlocati at gmail dot com
Operating system: Windows
PHP version: Irrelevant
Package: Output Control
Bug Type: Feature/Change Request
Bug description:Add a way if output is redirected
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 bug report at https://bugs.php.net/bug.php?id=72896&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72896&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72896&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72896&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72896&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72896&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72896&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72896&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72896&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72896&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72896&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72896&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72896&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72896&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72896&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72896&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72896&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72896&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72896&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72896&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72896&r=mysqlcfg