Execute a command and throw an exception if the return code is not 0.

@param string $command Command to execute

@return string Returns the output of the command as a string
@throws \RuntimeException on error.
356549
public function exec($command)
    {
        $this->debug("Executing: $command");
        $output = $returnValue = null;
        exec($command, $output, $returnValue);

        if ($returnValue != 0) {
            throw new \RuntimeException('Error executing command: '
                . $command . ' : ' . implode("\n", $output));
        }

        return implode("\n", $output);
    }
527172
protected function prepareCommand($command)
    {
        if (is_string($command)) {
            return trim($command);
        }
        if (is_array($command)) {
            return implode(' && ', $command);
        }
        throw new TaskExecutionException('Command must be string or array, ' . gettype($command) . ' given.', 1312454906);
    }
1073509
public function run(string $command) : int
    {
        $output = [];
        $returnVar = 1;

        $command .= $this->isWindows() ? $this->STD_ERR_PIPE_WIN : $this->STD_ERR_PIPE;

        exec($command, $output, $returnVar);

        return $returnVar;
    }
1094130
public String get(String command) throws PHPException {
		try {
			String s = php.execGet(command);
			flushContent();
			return s;
		} catch (IOException e) {
			LOGGER.error("IO Error with PhpDriver : " + e.toString());
			throw new IOErrorException(flushContentAndDropIOException());
		}
	}
425668
public function executeCommand($command)
    {
        $cmd = sprintf('%s %s', $this->binaryPath, $command);
        $p = new Process($cmd);
        $p->run();
        if ($p->isSuccessful()) {
            return $p->getOutput();
        } else {
            throw new \RuntimeException(sprintf('pygmentize failed with the error: %s', $p->getErrorOutput()));
        }
    }
723587
public function execute(Command $command)
    {
        if (!$command->isValid()) {
            throw new Exception('Invalid API command supplied');
        }

        $result = $this->curl()->post($this->getUrl($command), $command->getData());
        $type = $this->getResponseType();

        return new Response($result->getData(), $type);
    }
363173
protected function executeCommand($command) {
        $class = $this->config['commands'][$command]['class'];

        if (!class_exists($class) ||
            !is_subclass_of($class, __NAMESPACE__ . '\\Command\\Executes')
        ) {
            throw new RuntimeException(sprintf(
                'Command "%s" not found',
                $command
            ), ExitApp::BAD_USER_INTERACTION);
        }

        $this->config['command'] = $command;

        /** @var Executes $command */
        $command = new $class($this->config, $this->log);

        foreach ($this->config['args'] as $help) {
            if (in_array($help, ['-h', '--help'])) {
                $command->printUsage();
                return;
            }
        }

        $command->setup()->execute()->tearDown();
    }
267303
public function execute(Command $command)
    {
        if (!$this->innerCommandBus) {
            throw new Exception('No inner bus defined for this decorator. Set an inner bus with setInnerBus()');
        }

        $response = $this->innerCommandBus->execute($command);

        $eventName = $this->getEventName($command);

        $this->dispatcher->dispatch($eventName, [$command]);

        return $response;
    }
1164630
public function executeProcess($command)
    {
        $process = new Process($command);
        $process->setTimeout(null);
        $output = $this->output;
        $callback = function ($type, $data) use ($output) {
            $output->writeln(trim($data));
        };
        $exitCode = $process->run($callback);
        return [$exitCode, trim($process->getOutput())];
    }
975954
private function run($command)
    {
        $application = $this->createApplication();
        $application->setAutoExit(false);

        $this->applicationTester = new ApplicationTester($application);

        $this->outputFile = tempnam('.', 'phpeg');

        return $this->applicationTester->run(array(
            'command' => $command,
            'input-file' => $this->inputFile,
            'output-file' => $this->outputFile
        ));
    }
852481
public static function getCommand($command)
    {
        if (!is_string($command) || strlen($command) < 1) {
            throw new BadMethodCallException('Parameter command is not a valid string');
        }
        $instance = self::getInstance();
        
        if (!isset($instance->commands[$command])) {
            throw new BadMethodCallException('Command "' . $command . '" is not a registered command');
        }
        
        return $instance->commands[$command];
    }
1314291
public function execute($command)
    {
        $deferred = new Deferred();

        if ($this->ending) {
            $deferred->reject(new RuntimeException('Shell is ending already'));
        } else {
            $this->pending []= $deferred;

            $this->sendCommand($command);
        }

        return $deferred->promise();
    }
1298598
public function runSingleCommand($command)
    {
        $cmd = 'php ' . $this->directory . 'app/console ';

        return $this->phpci->executeCommand($cmd . $command, $this->directory);
    }
268987
public function execute($command, array $arguments = array(), $cwd = null)
    {
        $arguments += $this->getGlobalArguments();

        try {
            $result = $this->adapter->execute($command, $arguments, $cwd);
        } catch (\Exception $e) {
            // @todo move to a generic error handler? Something similar to the ParserInterface
            if (preg_match('/url \'[^\']+\' non-existent/i', $e->getMessage()) ||
                preg_match('/file not found/i', $e->getMessage()) ||
                preg_match('/path not found/i', $e->getMessage())
            ) {
                throw new NotFoundException($e->getMessage());
            }

            throw $e;
        }

        return $result;
    }
321447
public function exec($command)
    {
        // run command
        $exit = -1;
        $logfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tika-error.log';
        $descriptors = [['pipe', 'r'], ['pipe', 'w'], ['file', $logfile, 'a']];
        $process = proc_open($command, $descriptors, $pipes);
        $callback = $this->callback;

        // get output if command runs ok
        if(is_resource($process))
        {
            fclose($pipes[0]);
            $this->response = '';
            while($chunk = stream_get_line($pipes[1], $this->chunkSize))
            {
                if(!is_null($callback))
                {
                    $callback($chunk);
                }

                $this->response .= $chunk;
            }
            fclose($pipes[1]);
            $exit = proc_close($process);
        }

        // exception if exit value is not zero
        if($exit > 0)
        {
            throw new Exception("Unexpected exit value ($exit) for command $command");
        }

        return trim($this->response);
    }
49604
private function execute(Command $command)
    {
        $exec = $this->exec;
        $exec->setCommand($command);
        $code = $exec->run();
        $output = $exec->getOutput();

        if ($exec->hasErrors()) {

            switch ($code) {
                case 127:
                    $msg = 'git command not found, make sure it is installed an in the system path';
                    break;
                default:
                    $msg = 'Git execution failed : ' .$code . ' ' . $output['stderror'];
                    break;
            }

            throw new \RuntimeException($msg, $code);
        }

        return $code;
    }
1238818
public function getCommand($command): Command
    {
        if (isset($this->aliases[$command])) {
            return $this->aliases[$command];
        }

        if (isset($this->commands[$command])) {
            return $this->commands[$command];
        }

        throw new CommandNotFoundException($this, $command);
    }