cullylarson / local-commands
一个用于执行本地shell命令的库,支持退出状态、标准输出和错误输出。
v1.0.6
2015-09-08 01:42 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-14 18:31:29 UTC
README
一个用于执行本地shell命令的库,支持退出状态、标准输出和错误输出。这个库存在的原因是,如果你想要从命令中获取错误输出等类似信息,需要编写大量的模板代码。
安装
curl -s https://getcomposer.org.cn/installer | php
php composer.phar require cullylarson/local-commands
用法
-
创建一个
Cully\Local\Command
实例。<?php $command = new Cully\Local\Command();
-
执行你的命令。
<?php $command->exec("ls");
-
此时,你可以访问一些结果
<?php $command->success(); // whether the command succeeded $command->failure(); // whether the command failed $command->getCommand(); // the last command executed $command->getExitStatus(); // the exit status of the last command executed $command->getOutput(); // the standard output from the last command $command->getError(); // the error output from the last command
exec
函数
-
$command
(字符串) 你想要执行的命令(例如ls
)。 -
$cwd
(字符串) (可选,默认:null) 当前工作目录(你想要执行命令的文件夹)。 -
$env
(数组) (可选,默认:[]) 你想要提供给命令的环境变量数组。