How can I detect STDOUT redirection in PHP CLI?

天大地大妈咪最大 提交于 2019-12-21 20:15:16

问题


I've a PHP CLI script that uses shell escape sequences for bolding, but I want to be able to disable these automatically when the script's being redirected (eg to a log file).

I can find ways to detect STDOUT redirection in everything but PHP so far... so can anyone tell me how it is done in PHP?


回答1:


This should give you what you want:

if(posix_isatty(STDOUT))
    echo "No Redirection";
else
    echo "Redirection!";


来源:https://stackoverflow.com/questions/5730268/how-can-i-detect-stdout-redirection-in-php-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!