PHP shell_exec() vs exec()

442次阅读
没有评论

共计 840 个字符,预计需要花费 3 分钟才能阅读完成。

shell_exec() 和 exec()的区别是什么?

shell_exec

returns all of the output stream as a string.

exec

returns the last line of the output by default, but can provide all output as an array specifed as the second parameter.

See

Here are the differences. Note the newlines at the end.

> shell_exec('date')
string(29) "Wed Mar  6 14:18:08 PST 2013\n"
> exec('date')
string(28) "Wed Mar  6 14:18:12 PST 2013"

> shell_exec('whoami')
string(9) "mark\n"
> exec('whoami')
string(8) "mark"

> shell_exec('ifconfig')
string(1244) "eth0      Link encap:Ethernet  HWaddr 10:bf:44:44:22:33  \n  TX bytes:2779457335 (2.7 GB)\n"...
> exec('ifconfig')
string(0) ""
exec('ls', $out);
var_dump($out);
// Look an array

$out = shell_exec('ls');
var_dump($out);
// Look -- a string with newlines in it
exec('ls', $out, $status);
if (0 === $status) {
    var_dump($out);
} else {
    echo "Command failed with status: $status";
}

 

正文完
 1
BlackBeans
版权声明:本站原创文章,由 BlackBeans 2023-09-27发表,共计840字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。