为什么没有"执行"执行命令直到我打印输出?

时间:2016-04-19 06:37:01

标签: php linux unix clear

我在Ubuntu 14.04,PHP 5.5.9。在那里,我有一个非常简单的文件a.php

<?php

$a = exec('clear');
print($a);

如果我现在运行脚本,我得到:

$ php a.php 
<screen cleared> # nothing is displayed in the screen
                 # "clear" was performed successfully

但是,如果我评论print($a)只是有这样的文件:

<?php

$a = exec('clear');
然后没有任何反应:

$ php a.php 
$               # nothing happened, I see the previous line above

据我了解,调用变量$a是为了让clear执行。但它没有多大意义,因为exec() docs说:

  

exec - 执行外部程序

clear被调用之前,print()是否有理由不执行?

请注意,这与问题Clear CMD-shell with php有关,但我在这里问为什么会发生这种情况。

1 个答案:

答案 0 :(得分:2)

实际上,在调用exec时会执行clear。在实际输出之前,你只是在屏幕上看不到它的动作。