当前位置:网站首页>[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.
边栏推荐
猜你喜欢

PHP入门(自学笔记)

1.13 学习JS

Living to detect the Adaptive Normalized Representation Learning for GeneralizableFace Anti - Spoofing reading notes

IP access control: teach you how to implement an IP firewall with PHP

MySql高级 -- 约束

点名系统和数组元素为对象的排序求最大值和最小值
![[league/climate] A robust command-line function manipulation library](/img/ce/39114b1c74af649223db97e5b0e29c.png)
[league/climate] A robust command-line function manipulation library

微信小程序九宫格抽奖和转盘抽奖的实现

1.11今日学习

DOM manipulation---magnifying glass case
随机推荐
L1-039 古风排版(C)
点名系统和数组元素为对象的排序求最大值和最小值
[league/climate]一个功能健全的命令行功能操作库
简单黑马头条项目
(2)Thinkphp6模板引擎**标签
宝塔邮局邮箱设置成功后能发送不能接收问题处理
6.24今日学习
js 中this指向
三月底啦啦
稳定好用的短连接生成平台,支持API批量生成
Batch replace file fonts, Simplified -> Traditional
docker中配置mysql 5.7
每日五道面试题总结 22/7/20
PHP8.2 version release administrator and release plan
一分种一起来了解Vite的基础
PHP的几个有趣的打开方式:从基本到变态
PHP8.2将会有哪些新东西?
js takes the value of a feature at a certain position in the string, such as Huawei=> Huawei
page load process
1.13 学习JS