php 执行命令函数

简介: /** Method to execute a command in the terminal Uses : 1. system 2. passthru 3.
/**
    
Method to execute a command in the terminal
    
Uses :
 
    
1. system
    
2. passthru
    
3. exec
    
4. shell_exec
 
*/
function terminal($command)
{
    
//system
    if(function_exists('system'))
    {
        ob_start();
        system($command , $return_var);
        $output = ob_get_contents();
        ob_end_clean();
    }
    
//passthru
    else if(function_exists('passthru'))
    {
        ob_start();
        passthru($command , $return_var);
        $output = ob_get_contents();
        ob_end_clean();
    }
 
    
//exec
    else if(function_exists('exec'))
    {
        exec($command , $output , $return_var);
        $output = implode("n" , $output);
    }
 
    
//shell_exec
    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);
}
terminal('ls');

 

目录
相关文章
|
8天前
|
PHP Perl
PHP-ereg()函数
但再次强调,不建议使用ereg()函数,而应该改用preg_match()函数来执行更灵活和强大的正则表达式匹配操作。
19 4
|
12天前
|
存储 PHP 数据库
【PHP开发专栏】PHP数组操作与常见函数
【4月更文挑战第29天】本文介绍了PHP中的数组及其操作,包括定义与初始化、访问与修改、遍历。还探讨了常用的数组函数,如count()、in_array()、array_push/pop()、array_shift/unshift()、array_merge()、array_keys/values()以及sort()和rsort(),帮助开发者更有效地处理和操作数组。
|
13天前
|
运维 JavaScript Serverless
Serverless 应用引擎产品使用之在阿里函数计算中,Php环境,配置取消禁止函数exec如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
29 4
|
1月前
|
JSON PHP 数据格式
php函数
php函数
7 0
|
1月前
|
PHP
php事务删除加调用日志函数
php事务删除加调用日志函数
8 1
|
3月前
|
PHP
从建站到拿站 -- PHP判断循环及函数
从建站到拿站 -- PHP判断循环及函数
14 0
|
3月前
|
PHP
从PHP开始学渗透 -- 函数
从PHP开始学渗透 -- 函数
8 0
php案例:判断这个是繁体字还是简体字(满足绝大部分字符)用php函数
php案例:判断这个是繁体字还是简体字(满足绝大部分字符)用php函数
php案例:判断这个是繁体字还是简体字(满足绝大部分字符)用php函数
|
4月前
|
PHP 数据安全/隐私保护