I have a php file which currently puts in the browser the output of a bash script:
<?php
ob_implicit_flush(true);
ob_end_flush();
$cmd = "./bash_script.sh";
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
echo '<pre>';
if (is_resource($process)) {
while ($s = fgets($pipes[1])) {
print $s;
}
}
echo '</pre>';
?>
However, in CLI the output of my bash_script.sh is colored formatted but in the browser output there is no formatting and colors are not visible.
I have tried the following simple example with command ls --color:
<?php
$cmd = "ls --color";
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
echo '<pre>';
if (is_resource($process)) {
while ($s = fgets($pipes[1])) {
print $s;
}
}
echo '</pre>';
?>
And its output comes with color codes (or at least I believe so), that is:
[01;34mFolder1[0m
[01;34mFolder2[0m
[01;34mFolder3[0m
[01;32mFile1[0m
[01;34mFolder4[0m
However, with my script, those color codes don't appear.
Is it possible to print the same colored output I get in CLI to the browser?
bash_script.sh?