当前位置:网站首页>[mikehaertl/php-shellcommand] A library for invoking external command operations
[mikehaertl/php-shellcommand] A library for invoking external command operations
2022-08-02 03:55:00 【phpreturn】
It provides a simple method interface to call and manipulate external commands, which can be used to replace exec.
Compared with calling exec directly, it has the following features:
- Capture, stdOut, stdErr, exitCode
- Handling complex parameters
- Support environment variables and other parameters
- Support for pipeline resources, such as files or streams
- Timeout can be executed
Basic usage
execute()) {echo $command->getOutput();} else {echo $command->getError();$exitCode = $command->getExitCode();}
Advanced usage
Add parameter
addArg('--name=', "d'Artagnan");// Add argument with several values// results in --keys key1 key2$command->addArg('--keys', array('key1','key2'));
String input
setStdIn('{"foo": 0}');if (!$command->execute()) {echo $command->getError();} else {echo $command->getOutput();}// Output:// {// "foo": 0// }
Use file content as input
setStdIn($fh);if (!$command->execute()) {echo $command->getError();} else {echo $command->getOutput();}fclose($fh);
Take URL content as input
setStdIn($fh);if (!$command->execute()) {echo $command->getError();} else {echo $command->getOutput();}fclose($fh);
Encapsulate the command
'/usr/local/bin/mycommand',// Will be passed as environment variables to the command'procEnv' => array('DEMOVAR' => 'demovalue'),// Will be passed as options to proc_open()'procOptions' => array('bypass_shell' => true,),));
Support more parameter methods
Support how many methods we need to call external command book, such as getting output, getting error, getting exit code, etc.
边栏推荐
猜你喜欢
随机推荐
What are the PHP framework?
PHP基金会三月新闻公告发布
PHP有哪些杀手级超厉害框架或库或应用?
6.24今日学习
微信小程序自定义swiper轮播图面板指示点|小圆点|进度条
2.PHP变量、输出、EOF、条件语句
Thread Pool (Introduction and Use of Thread Pool)
MySql高级 -- 约束
百度定位js API
5.20今日学习
[campo/random-user-agent]随机伪造你的User-Agent
SQL: DDL, DML, DQL, DCL corresponding introduction and demonstration
Batch replace file fonts, Simplified -> Traditional
Dom实现input的焦点触发
Function hoisting and variable hoisting
微信小程序全局组件的定义
(5) 模块与包、编码格式、文件操作、目录操作
[sebastian/diff]一个比较两段文本的历史变化扩展库
DVWA靶机安装教程
Guangzhou Huawei Interview Summary