cullylarson / local-commands
A library for executing local shell commands, with support for exit status, standard output, and error output.
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-11-09 19:30:28 UTC
README
A library for executing local shell commands, with support for exit status, standard output, and error output. The reason this exists is that there's a lot of boiler plate code necessary if you want to get stuff like error output from a command.
Install
curl -s http://getcomposer.org/installer | php
php composer.phar require cullylarson/local-commands
Usage
-
Create an instance of
Cully\Local\Command
.<?php $command = new Cully\Local\Command();
-
Execute your command.
<?php $command->exec("ls");
-
At this point, you have access to a few results:
<?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
The exec
Function
-
$command
(string) The command you want to execute (e.g.ls
). -
$cwd
(string) (optional, default: null) The current working directory (the folder you want to execute the command in). -
$env
(array) (optional, default: []) An array of environment variable that you want to make available to the command.