2017 © Pedro Peláez
 

library php-shell

PHP wrapper for executing shell commands

image

synapse/php-shell

PHP wrapper for executing shell commands

  • Monday, April 18, 2016
  • by synapse
  • Repository
  • 1 Watchers
  • 2 Stars
  • 49 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

PHP Shell

Build Status, (*1)

Introduction

PHP Shell was written to provide an OOP wrapper around shell command execution in PHP. It enables you to receive a response object from the command execution containing the stdout, stderr and exit code of the command., (*2)

Documentation

Basic usage

To create the command, pass an absolute path to the command for instantiation. You can also set where the command is executed using the setWorkingDirectory method., (*3)

$pwd = new Neuron\Shell\Command('/bin/pwd'); // CommandNotFoundException if the command is not executable
$pwd->setWorkingDirectory('/tmp'); // DirectoryDoesNotExistException if the directory is not found
$output = $pwd->execute();
var_dump($output->getStdout()); // string(5) "/tmp"
var_dump($output->getStderr()); // string(0) ""
var_dump($output->getExitCode()); // int(0)

Adding flags

$cmd = new Neuron\Shell\Command('/usr/local/bin/my_command');
$cmd->addShortFlag('v');
$cmd->addShortFlag('c', '/tmp/test.json');
$cmd->addLongFlag('version');
$cmd->addLongFlag('config', '/tmp/test.json');

Adding Arguments

$echo = new Neuron\Shell\Command('/bin/echo');
$echo->addArgument('hi there!');

Piping through another command

$cmd = new Neuron\Shell\Command('/usr/local/bin/my_command');
$cmd2 = new Neuron\Shell\Command('/usr/local/bin/my_command2');
$cmd->pipe($cmd2);
echo $cmd->getCmdString(); // "/usr/local/bin/my_command | /usr/local/bin/my_command2"

Searching Output

Check if the command was successful using the wasSuccessful method. Check if the output contains a certain string using the stdoutContains and stderrContains methods., (*4)

$echo = new \Neuron\Shell\Command('/bin/echo');
$echo->addArgument('fruit banana');
$output = $echo->execute();
var_dump($output->wasSuccessful()); // bool(true)
var_dump($output->stdoutContains('apple')); // bool(false)
var_dump($output->stdoutContains('banana')); // bool(true)

License

PHP Shell is open-sourced software licensed under the MIT license, (*5)

Changelog

1.1.1

  • Adding README info for pipe functionality

1.1.0

  • Adding pipe functionality

1.0.0

  • Initial Release

The Versions

18/04 2016

dev-master

9999999-dev

PHP wrapper for executing shell commands

  Sources   Download

MIT

The Development Requires

by Iain Earl

18/04 2016

1.1.1

1.1.1.0

PHP wrapper for executing shell commands

  Sources   Download

MIT

The Development Requires

by Iain Earl

18/04 2016

1.1.0

1.1.0.0

PHP wrapper for executing shell commands

  Sources   Download

MIT

The Development Requires

by Iain Earl

15/04 2016

1.0.0

1.0.0.0

PHP wrapper for executing shell commands

  Sources   Download

MIT

The Development Requires

by Iain Earl