FreeBSD Execute System Commands_PHP Tutorial

WBOY
Release: 2016-07-20 11:07:50
Original
1031 people have browsed it

FreeBSD executes system commands

FreeBSD executes system commands

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;
}

//Determine the location of the executable file 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; Method


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


http://www.bkjia.com/PHPjc/444944.html
www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/444944.htmlTechArticleFreeBSD Execute system command FreeBSD Execute system command function do_command($commandName, $args) { $buffer = ; if ( false === ($command = find_command($commandName))) return false; if...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!