PHP中exec函数和shell_exec函数的区别
这两个函数都是执行Linux命令函数,不同的是获取返回结果不一样,exec只能获取最后一行数据,shell_execu则可以获取全部数据。
假如脚本路径下有如下文件:
-bash-4.1#ll 总用量12 -rw-rw-r--.1wwwweb133 7月1615:00a.php -rw-r--r--.1leeweb 59 2月2917:05b.php -rw-r--r--.1leeweb 81 3月 817:00c.php
exec例子
<?php
/**
*exec与shell_exec的区别
*琼台博客
*/
$data=exec('/bin/ls-l');
echo'<pre>';
print_r($data);
echo'</pre>';
?>
执行结果
-rw-r--r--.1leeweb 81Mar 817:00c.php
shell_exec例子
<?php
/**
*exec与shell_exec的区别
*琼台博客
*/
$data=shell_exec('/bin/ls-l');
echo'<pre>';
print_r($data);
echo'</pre>';
?>
执行结果
total12 -rw-rw-r--.1wwwweb139Jul16 2012a.php -rw-r--r--.1leeweb 59Feb2917:05b.php -rw-r--r--.1leeweb 81Mar 817:00c.php
所以平时使用exec函数的童鞋注意了,如果你需要获取全部返回信息,就应该使用shell_exec函数,当然,如果命令执行结果只有一行返回信息,那么使用哪个都无所谓。
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便