当前位置:网站首页>[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.
边栏推荐
- IO streams, byte stream and byte stream buffer
- About the apache .htaccess file of tp
- MySql Advanced -- Constraints
- Function hoisting and variable hoisting
- 4.14到新公司的一天
- QR code generation API interface, which can be directly connected as an A tag
- 1.初识PHP
- (6) 学生信息管理系统设计
- [mikehaertl/php-shellcommand]一个用于调用外部命令操作的库
- 微信小程序云开发之券码领取,怎么防止用户领取到相同的数据?
猜你喜欢
随机推荐
Various ways of AES encryption
PHP image compression to specified size
The querystring module
1.8今日学习
[symfony/mailer]一个优雅易用的发送邮件类库
PHP8.2的版本发布管理员和发布计划
百度定位js API
每日面试题 2022/7/28
SQL: DDL, DML, DQL, DCL corresponding introduction and demonstration
1.13 学习JS
MySql Advanced -- Constraints
URL URL
使用PHPMailer发送邮件
Relative and absolute paths
4.14到新公司的一天
Batch replace file fonts, Simplified -> Traditional
4.表单与输入
PHP有哪些杀手级超厉害框架或库或应用?
[campo/random-user-agent]随机伪造你的User-Agent
(6) 学生信息管理系统设计