I have code like this in php:
header("Content-Type: text/plain");
exec("/bin/bash -c 'ls --color=always'", $result);
echo implode("\n", $result);
and I've got result (escape is not visible)
Makefile
README
Yann Tiersen - Comptine d'un autre ete L'apres midi.mp3
bush-src.js
bush.js
bush.min.js
[0m[01;34mcgi-bin[0m
config.json
[01;34mcss[0m
favicon.ico
foo.png
index.php
[01;34mlib[0m
ls.txt
test.php
test.php~
[01;32mtest.txt[0m
It show ANSI escape codes for directories and executable files, but when I call from command line
php -r "exec('bash -c \"ls --color=always\"', \$result);echo implode(\"\\n\", \$result);" | less
I've got this:
bush.js
bush.min.js
bush-src.js
ESC[0mESC[01;34mcgi-binESC[0m
config.json
ESC[01;34mcssESC[0m
favicon.ico
ESC[01;35mfoo.pngESC[0m
index.php
ESC[01;34mlibESC[0m
ls.txt
Makefile
README
test.php
test.php~
ESC[01;32mtest.txtESC[0m
ESC[00;36mYann Tiersen - Comptine d'un autre ete L'apres midi.mp3ESC[0m
png and mp3 have ANSI escapes codes, why php exec from webpage don't give that as return?
$LS_COLORS
variable defined somewhere in your~/.bashrc
/~/.zshrc
... (probably via a call ofeval "$(dircolors)"
)if [ -x /usr/bin/dircolors ]; then eval "
dircolors -b" fi