protected function _run($input)
    {
        $this->_output = '';
        $this->_errorOutput = '';

        $descriptors = array(
            0 => array('pipe', 'r'),
            1 => array('pipe', 'w'),
            2 => array('pipe', 'w'),
        );
        $pipes = array();

        $childProcess = proc_open($this->toCommandString(), $descriptors, $pipes);

        if (!is_resource($childProcess)) {
            throw new \RuntimeException('Unable to run command: ' . $this->toCommandString());
        }

        if (null !== $input) {
            fwrite($pipes[0], $input);
            fclose($pipes[0]);
        }

        $output = stream_get_contents($pipes[1]);
        fclose($pipes[1]);

        $errorOutput = stream_get_contents($pipes[2]);
        fclose($pipes[2]);

        $exitCode = proc_close($childProcess);

        // Run the piped command, if any
        if ($this->hasPipedCommand()) {
            $pipedCommand = $this->getPipedCommand();

            $pipedCommand->run($output);

            $output      = $pipedCommand->getOutput();
            $exitCode    = $pipedCommand->getExitCode();
            $errorOutput = $pipedCommand->getErrorOutput();
        }

        $this->_output = $output;
        $this->_errorOutput = $errorOutput;

        return $exitCode;
    }