php system()和exec()差别
生活随笔
收集整理的這篇文章主要介紹了
php system()和exec()差别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、exec? ---執行外部程序
string exec ( string $command [, array &$output [, int &$return_var ]] )$command? ?要執行的shell 命令
$output? ? ? ? shell命令的輸出填充此數組,每行輸出填充數組中的一個元素。?請注意,如果數組中已經包含了部分元素,exec()?函數會在數組末尾追加內容。如果你不想在數組末尾進行追? ? ? ? ? ? ? ? ? ? ? ?加,請在傳入?exec()?函數之前 對數組使用?unset()?函數進行重置。
$return_var? 命令執行后的返回狀態,命令執行成功值是0
返回值? ? ? ? ?shell命令輸出的最后一行
ps:? ?2>&1??exec不成功,調試方案一個技巧就是使用管道命令, 使用?2>&1, 命令就會輸出shell執行時的錯誤到$output變量, 輸出該變量即可分析。
?
?例子1
(1)代碼所在的index.php 文件的結構
(2)代碼
??
$out = [34]; $res = exec('ls 2>&1',$out,$return_status); var_dump($res); echo '------'; var_dump($out); echo '------'; var_dump($return_status);(3)執行結果
zhangxueqing:demo playcrab$ php ./1/index.php /Users/playcrab/www/demo/1/index.php:10: string(11) "webuploader" ------/Users/playcrab/www/demo/1/index.php:12: array(10) {[0] =>int(34)[1] =>string(1) "1"[2] =>string(6) "1.html"[3] =>string(5) "1.php"[4] =>string(10) "client.php"[5] =>string(14) "design-pattern"[6] =>string(3) "img"[7] =>string(17) "jquery.blockUI.js"[8] =>string(10) "static.php"[9] =>string(11) "webuploader" } ------/Users/playcrab/www/demo/1/index.php:14: int(0)二、system ---執行外部程序,并且顯示輸出
?
1 string system ( string $command [, int &$return_var ] )$command? 要執行的命令
$return_var? 命令執行后的返回狀態,值是0表示成功
?1.示例代碼
$res = system('ls 2>&1',$return_status); var_dump($res); echo '------'; var_dump($return_status);2.輸出結果
?
?
?
轉載于:https://www.cnblogs.com/zxqblogrecord/p/9755984.html
總結
以上是生活随笔為你收集整理的php system()和exec()差别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP重写
- 下一篇: [Swift]LeetCode326.