狮子座男

导航

PHP使用可跨平台的函数执行命令

function terminal($command)
{
    if(function_exists('system'))
        {
        ob_start();
        system($command,$return_var);
        $output=ob_get_contents();
        ob_end_clean();
    }else if(function_exists('passthru'))
        {
        ob_start();
        passthru($command,$return_var);
        $output = ob_get_contents();
        ob_end_clean();
    }else if(function_exists('exec'))
        {    
        exec($command,$output,$return_var);
        $output = implode("\n",$output);
    }else if(function_exists('shell_exec'))
        {
        $output = shell_exec($command);
    }else
        {
        $output = 'Command execution not possible on this system';
        $return_var = 1;
    }
    return array('output'=>$output,'status'=>$return_var);
}

 

posted on 2014-09-01 15:59  狮子座男  阅读(133)  评论(0)    收藏  举报