public function run($cmd, $args = array(), $stdin = null) {

    $cmd = $this->buildCommand($cmd, $args);

    $process = proc_open($cmd, $this->descSpecs, $pipes, $this->_cwd, $this->_env);

    if(is_resource($process)) {

      /* Write stuff to STDIN, and close it. */
      fwrite($pipes[self::STDIN], $stdin);
      fclose($pipes[self::STDIN]);

      /* Read STDOUT and STDERR. */
      $out['STDOUT'] = stream_get_contents($pipes[self::STDOUT]);
      $out['STDERR'] = stream_get_contents($pipes[self::STDERR]);

      /* Close STDOUT and STDERR to aviod potential deadlocks. */
      fclose($pipes[self::STDOUT]);
      fclose($pipes[self::STDERR]);

      /* Close process and get return value. */
      $out['return'] = proc_close($process);

      return $out;
    }
    return false;
  }
public function run($cmd, $args = array(), $stdin = null) {

    $cmd = $this->buildCommand($cmd, $args);

    $process = proc_open($cmd, $this->descSpecs, $pipes, $this->_cwd, $this->_env);

    if(is_resource($process)) {

      /* Write stuff to STDIN, and close it. */
      fwrite($pipes[self::STDIN], $stdin);
      fclose($pipes[self::STDIN]);

      /* Read STDOUT and STDERR. */
      $out['STDOUT'] = stream_get_contents($pipes[self::STDOUT]);
      $out['STDERR'] = stream_get_contents($pipes[self::STDERR]);

      /* Close STDOUT and STDERR to aviod potential deadlocks. */
      fclose($pipes[self::STDOUT]);
      fclose($pipes[self::STDERR]);

      /* Close process and get return value. */
      $out['return'] = proc_close($process);

      return $out;
    }
    return false;
  }
public function run ( $ cmd , $ args = array ( ) , $ stdin = null ) { $ cmd = $ this -> buildCommand ( $ cmd , $ args ) ; $ process = proc_open ( $ cmd , $ this -> descSpecs , $ pipes , $ this -> _cwd , $ this -> _env ) ; if ( is_resource ( $ process ) ) { /* Write stuff to STDIN, and close it. */ fwrite ( $ pipes [ self :: STDIN ] , $ stdin ) ; fclose ( $ pipes [ self :: STDIN ] ) ; /* Read STDOUT and STDERR. */ $ out [ 'STDOUT' ] = stream_get_contents ( $ pipes [ self :: STDOUT ] ) ; $ out [ 'STDERR' ] = stream_get_contents ( $ pipes [ self :: STDERR ] ) ; /* Close STDOUT and STDERR to aviod potential deadlocks. */ fclose ( $ pipes [ self :: STDOUT ] ) ; fclose ( $ pipes [ self :: STDERR ] ) ; /* Close process and get return value. */ $ out [ 'return' ] = proc_close ( $ process ) ; return $ out ; } return false ; }
Execute an external program.

This method uses as PDO like syntax to build commands.

@param string $cmd
Command to execute. If you need to pass arguments to a command. A PDO like syntax can be used.
For example: "ls -lsa %path".

@param array $args
An associative array containing the arguments to pass to $cmd.
For example: array('%path' => '/home');

@param string $stdin
If the command requests input (e.g. a passphrase) this can be
passed here. Note that if a command requires multiple feedbacks
from a user this method can not be used.

@return array
Returns an array containing return value and results from STDOUT and STDERR.
Execute an external program .