当前位置:网站首页>[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.
边栏推荐
猜你喜欢
随机推荐
稳定好用的短连接生成平台,支持API批量生成
[phpunit/php-timer]一个用于代码执行时间的计时器
Relative and absolute paths
[vite] Failed to parse source for import analysis because the content contains invalid JS syntax.
每日五道面试题总结 22/7/26
面试总结 22/7/25 面试中的重点
每日五道面试题 2022/7/27
(2)Thinkphp6模板引擎**标签
docker中配置mysql 5.7
PHP8.2中字符串变量解析的新用法
Dom实现input的焦点触发
js 正则中 replace() 使用
批量替换文件字体,简体->繁体
每日五道面试题总结 22/7/23
SQL classification, DQL (Data Query Language), and corresponding SQL query statement demonstration
The Error in the render: "TypeError: always read the properties of null '0' (reading)" Error solution
[symfony/finder]最好用的文件操作库
js预编译 GO 和AO
一分种一起来了解Vite的基础
PHP基金会三月新闻公告发布