cullylarson/local-commands

A library for executing local shell commands, with support for exit status, standard output, and error output.

v1.0.6 2015-09-08 01:42 UTC

This package is not auto-updated.

Last update: 2024-04-27 16:08:51 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

  1. Create an instance of Cully\Local\Command.

    <?php
    
    $command = new Cully\Local\Command();
    
  2. Execute your command.

    <?php
    
    $command->exec("ls");
    
  3. 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

  1. $command (string) The command you want to execute (e.g. ls).

  2. $cwd (string) (optional, default: null) The current working directory (the folder you want to execute the command in).

  3. $env (array) (optional, default: []) An array of environment variable that you want to make available to the command.