PHP執(zhí)行l(wèi)inux命令的6個函數(shù)
<?php $test = 'ls /tmp/test'; //ls是linux下的查目錄,文件的命令exec($test,$array); //執(zhí)行命令print_r($array);?> 返回結(jié)果如下:
[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函數(shù)
<?php $test = 'ls /tmp/test';$last = system($test);print 'last: $lastn';?> 返回結(jié)果:
[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函數(shù)
<?php $test = 'ls /tmp/test';passthru($test);?> 4,popen函數(shù)
<?php $test = 'ls /tmp/test';$fp = popen($test,'r'); //popen打一個進(jìn)程通道 while (!feof($fp)) { //從通道里面取得東西 $out = fgets($fp, 4096); echo $out; //打印出來} pclose($fp);?> 5,proc_open函數(shù)
<?php $test = 'ls /tmp/test';$array = array( array('pipe','r'), //標(biāo)準(zhǔn)輸入 array('pipe','w'), //標(biāo)準(zhǔn)輸出內(nèi)容 array('pipe','w') //標(biāo)準(zhǔn)輸出錯誤 ); $fp = proc_open($test,$array,$pipes); //打開一個進(jìn)程通道echo stream_get_contents($pipes[1]); //為什么是$pipes[1],因為1是輸出內(nèi)容proc_close($fp);?> 6,shell_exec函數(shù)
<?php $test = 'ls /tmp/test';$out = shell_exec($test);echo $out;?> popen,passthru,proc_open,shell_exec的返回結(jié)果如下:
[root@krlcgcms01 shell]# php test.php 1001.log 10.log 10.tar.gz aaa.tar.gz mytest test1101 test1102 weblog_2010_09 我能發(fā)現(xiàn)的就這幾個函數(shù),能執(zhí)行l(wèi)inux下的命令,我想應(yīng)當(dāng)還有吧,歡迎大家補(bǔ)充。 來自:http://blog.51yip.com/php/1064.html
相關(guān)文章:
1. msxml3.dll 錯誤 800c0019 系統(tǒng)錯誤:-2146697191解決方法2. jsp+servlet簡單實現(xiàn)上傳文件功能(保存目錄改進(jìn))3. 解析原生JS getComputedStyle4. 輕松學(xué)習(xí)XML教程5. HTML DOM setInterval和clearInterval方法案例詳解6. 阿里前端開發(fā)中的規(guī)范要求7. xpath簡介_動力節(jié)點Java學(xué)院整理8. jsp EL表達(dá)式詳解9. css代碼優(yōu)化的12個技巧10. jsp實現(xiàn)登錄驗證的過濾器
