I am onUbuntu 14.04, with PHP 5.5.9. There, I have a very simple file a.php
:
<?php
$a = exec('clear');
print($a);
If I run the script as is now I get:
$ php a.php
<screen cleared> # nothing is displayed in the screen
# "clear" was performed successfully
However, if I comment the print($a)
to just have a file like this:
<?php
$a = exec('clear');
then nothing happens:
$ php a.php
$ # nothing happened, I see the previous line above
To my understanding, it is the call to the variable $a
what makes clear
to be performed. But it doesn't make much sense, since exec() docs says:
exec — Execute an external program
Is there a reason why clear
doesn't get performed until print()
is called?
Note this is related to the question Clear CMD-shell with php but I am asking here why this happens.