PHP 系统命令函数

 1 function execute($cmd) {
 2     $res = '';
 3     if ($cmd) {
 4         if(function_exists('system')) {
 5             @ob_start();
 6             @system($cmd);
 7             $res = @ob_get_contents();
 8             @ob_end_clean();
 9         } elseif(function_exists('passthru')) {
10             @ob_start();
11             @passthru($cmd);
12             $res = @ob_get_contents();
13             @ob_end_clean();
14         } elseif(function_exists('shell_exec')) {
15             $res = @shell_exec($cmd);
16         } elseif(function_exists('exec')) {
17             @exec($cmd,$res);
18             $res = join(“\n",$res);
19         } elseif(@is_resource($f = @popen($cmd,"r"))) {
20             $res = '';
21             while(!@feof($f)) {
22                 $res .= @fread($f,1024);
23             }
24             @pclose($f);
25         }
26     }
27     return $res;
28 }

 

你可能感兴趣的:(PHP)