Home > php教程 > php手册 > FreeBSD 执行系统命令

FreeBSD 执行系统命令

WBOY
Release: 2016-05-25 16:38:30
Original
810 people have browsed it

<?php 
function do_command($commandName, $args) 
{ 
    $buffer = ""; 
    if (false === ($command = find_command($commandName))) return false; 
    if ($fp = @popen("$command $args", &#39;r&#39;)) 
    { 
        while (!@feof($fp)) 
        { 
         $buffer .= @fgets($fp, 4096); 
        } 
        return trim($buffer); 
    } 
    return false; 
}  
//确定执行文件位置 FreeBSD 
function find_command($commandName) 
{ 
    $path = array(&#39;/bin&#39;, &#39;/sbin&#39;, &#39;/usr/bin&#39;, &#39;/usr/sbin&#39;, &#39;/usr/local/bin&#39;, &#39;/usr/local/sbin&#39;); 
    foreach($path as $p) 
    { 
        if (@is_executable("$p/$commandName")) return "$p/$commandName"; 
    } 
    return false; 
}  
//调用方法 
echo do_command(&#39;sysctl&#39;, "-n hw.model");
Copy after login


永久地址:

转载随意~请带上教程地址吧^^

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template