PHP執行linux命令的6個函數
<?php $test = 'ls /tmp/test'; //ls是linux下的查目錄,文件的命令exec($test,$array); //執行命令print_r($array);?> 返回結果如下:
[root@krlcgcms01 shell]# php ./exec.php Array ( [0] => 1001.log [1] => 10.log [2] => 10.tar.gz [3] => aaa.tar.gz [4] => mytest [5] => test1101 [6] => test1102 [7] => weblog_2010_09 ) 2,system函數
<?php $test = 'ls /tmp/test';$last = system($test);print 'last: $lastn';?> 返回結果:
[root@krlcgcms01 shell]# php system.php 1001.log 10.log 10.tar.gz aaa.tar.gz mytest test1101 test1102 weblog_2010_09 last:weblog_2010_09 3,passthru函數
<?php $test = 'ls /tmp/test';passthru($test);?> 4,popen函數
<?php $test = 'ls /tmp/test';$fp = popen($test,'r'); //popen打一個進程通道 while (!feof($fp)) { //從通道里面取得東西 $out = fgets($fp, 4096); echo $out; //打印出來} pclose($fp);?> 5,proc_open函數
<?php $test = 'ls /tmp/test';$array = array( array('pipe','r'), //標準輸入 array('pipe','w'), //標準輸出內容 array('pipe','w') //標準輸出錯誤 ); $fp = proc_open($test,$array,$pipes); //打開一個進程通道echo stream_get_contents($pipes[1]); //為什么是$pipes[1],因為1是輸出內容proc_close($fp);?> 6,shell_exec函數
<?php $test = 'ls /tmp/test';$out = shell_exec($test);echo $out;?> popen,passthru,proc_open,shell_exec的返回結果如下:
[root@krlcgcms01 shell]# php test.php 1001.log 10.log 10.tar.gz aaa.tar.gz mytest test1101 test1102 weblog_2010_09 我能發現的就這幾個函數,能執行linux下的命令,我想應當還有吧,歡迎大家補充。 來自:http://blog.51yip.com/php/1064.html
相關文章:
1. ASP中常用的22個FSO文件操作函數整理2. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁3. ASP調用WebService轉化成JSON數據,附json.min.asp4. .Net core 的熱插拔機制的深入探索及卸載問題求救指南5. SharePoint Server 2019新特性介紹6. html清除浮動的6種方法示例7. 讀大數據量的XML文件的讀取問題8. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執行過程解析9. React+umi+typeScript創建項目的過程10. Vue+elementUI下拉框自定義顏色選擇器方式
