FreeBSD 执行系统命令_PHP教程

WBOY
Libérer: 2016-07-20 11:07:50
original
1007 Les gens l'ont consulté

FreeBSD 执行系统命令

 FreeBSD 执行系统命令

function do_command($commandName, $args)
    {
        $buffer = "";
        if (false === ($command = find_command($commandName))) return false;
        if ($fp = @popen("$command $args", 'r'))
            {
    while (!@feof($fp))
    {
     $buffer .= @fgets($fp, 4096);
    }
    return trim($buffer);
   }
        return false;
    }

//确定执行文件位置 FreeBSD

function find_command($commandName)
    {
        $path = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
        foreach($path as $p)
        {
            if (@is_executable("$p/$commandName")) return "$p/$commandName";
        }
        return false;
    }


 
//调用方法

 

echo do_command('sysctl', "-n hw.model");
 ?>


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444944.htmlTechArticleFreeBSD 执行系统命令 FreeBSD 执行系统命令 function do_command($commandName, $args) { $buffer = ; if (false === ($command = find_command($commandName))) return false; if...
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!