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;
  }