日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php system()和exec()差别

發布時間:2024/4/17 php 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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()差别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。