gpt4 book ai didi

php - 为什么 "exec"在我打印它的输出之前不执行命令?

转载 作者:太空宇宙 更新时间:2023-11-04 09:25:41 26 4
gpt4 key购买 nike

我使用的是 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 — Execute an external program

print() 被调用之前,clear 没有被执行是否有原因?

注意这与问题 Clear CMD-shell with php 有关但我要问的是为什么会发生这种情况。

最佳答案

实际上,clear是在调用exec的时候执行的。在实际输出之前,您只是看不到屏幕上的操作。

关于php - 为什么 "exec"在我打印它的输出之前不执行命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36710361/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com