Execute command

@return self Returns itself

@throws Exception on error
774116
public function execute() {
        $this->log
            ->printAsMessage()
            ->info($this->getDescription())
            ->printEmptyLine()
            ->printAsOutput();

        ksort($this->config['commands']);

        $maxCommandLength = 0;

        foreach (array_keys($this->config['commands']) as $command) {
            if (is_string($command) && strlen($command) > $maxCommandLength) {
                $maxCommandLength = strlen($command);
            }
        }

        $tab = 4;
        $minLength = $tab * (int) ($maxCommandLength / $tab) + $tab;

        foreach ($this->config['commands'] as $command => $details) {
            $this->log->info(
                str_pad($command, $minLength) . '<dim>' . $details['description'] . '</dim>'
            );
        }

        return $this;
    }
94018
protected function executeCommand($command)
    {
        $result = @exec($command, $output, $code);
        $output = implode("\n", $output);

        if ($result === false) {
            throw new Exception("Failed to execute command '$command' with message: [$code] '$output'");
        }

        return $output;
    }
223574
public function execAction()
    {
        //no action defined
        if(!$this->action) {
            throw new \Exception(sprintf('no action defined for subject %s', $this->name));
        }
        //exec method
        try {
            $this->checkTraitsInjections();
            $this->traitsInit();
            $this->{'exec'.$this->sanitizeAction($this->action)}();
        } catch(Exception $exception) {
        //no method defined
            throw new Exception(sprintf('no method for handling %s %s %s', AREA, $this->name, $this->action));
        }
    }
886584
public function execute()
    {
        if ($this->cursor) {
            return $this;
        }

        $this->db->execute();

        $this->cursor = $this->db->getCursor();

        return $this;
    }
89174
public static function getCommand(): Command
    {
        if (is_null(self::$exec)) {
            self::$exec = new Command();
        }
        return self::$exec;
    }
1050924
public function execute()
    {
        $stmt = $this->dbh->prepare($this->__toString());

        try {
            $success = $stmt->execute($this->getValues());
            if (!$success) {
                $info = $stmt->errorInfo();

                throw new Exception($info[2], $info[0]);
            }
        } catch (PDOException $e) {
            throw new Exception($e->getMessage(), $e->getCode(), $e);
        }

        return $stmt;
    }
586495
public function execute()
	{
		$query  = $this->factory->builder($this->insert)->process();
		$result = $this->pdo->query($query);
		if(!$result)
		{
			throw new \Exception('An error is while the insertion occurred! (query: "' . $query . '")');
		}

		return $this->pdo->lastInsertId();
	}
427770
public function execute()
    {
        try {
            $opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
            $pdo  = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, $opts);

            foreach ($this->queries as $query) {
                if (!is_array($query)) {
                    // Simple query
                    $pdo->query($this->phpci->interpolate($query));
                } elseif (isset($query['import'])) {
                    // SQL file execution
                    $this->executeFile($query['import']);
                } else {
                    throw new \Exception(Lang::get('invalid_command'));
                }
            }
        } catch (\Exception $ex) {
            $this->phpci->logFailure($ex->getMessage());
            return false;
        }
        return true;
    }
343429
public function executeCommand()
    {
        if ($this->rsyncPath === null) {
            throw new BuildException('The "rsyncPath" attribute is missing or undefined.');
        }

        if ($this->sourceDir === null) {
            throw new BuildException('The "sourcedir" attribute is missing or undefined.');
        } else {
            if ($this->destinationDir === null) {
                throw new BuildException('The "destinationdir" attribute is missing or undefined.');
            }
        }

        if (strpos($this->destinationDir, ':')) {
            $this->setIsRemoteConnection(true);
        }

        if (strpos($this->sourceDir, ':')) {
            if ($this->isRemoteConnection) {
                throw new BuildException('The source and destination cannot both be remote.');
            }
            $this->setIsRemoteConnection(true);
        } else {
            if (!(is_dir($this->sourceDir) && is_readable($this->sourceDir))) {
                throw new BuildException('No such file or directory: ' . $this->sourceDir);
            }
        }

        if ($this->backupDir !== null && $this->backupDir == $this->destinationDir) {
            throw new BuildException("Invalid backup directory: " . $this->backupDir);
        }

        $command = $this->getCommand();

        $output = [];
        $return = null;
        exec($command, $output, $return);

        $lines = '';
        foreach ($output as $line) {
            if (!empty($line)) {
                $lines .= "\r\n" . "\t\t\t" . $line;
            }
        }

        $this->log($command);

        if ($return != 0) {
            $this->log('Task exited with code: ' . $return, Project::MSG_ERR);
            $this->log(
                'Task exited with message: (' . $return . ') ' . $this->getErrorMessage($return),
                Project::MSG_ERR
            );
            throw new BuildException($return . ': ' . $this->getErrorMessage($return));
        } else {
            $this->log($lines, Project::MSG_INFO);
        }

        return $return;
    }
1363397
public function execute()
    {
        $this->prepareExecute();

        // Show help or not if command has no logic
        if (!count($this->children) && $this->console instanceof AbstractConsole && $this->console->get('show_help')) {
            $this->io->out($this->console->describeCommand($this));

            return $this->postExecute(true);
        }

        if (count($this->children) && count($this->io->getArguments())) {
            $name = $this->io->getArgument(0);

            // Show help if a command also has logic
            if ($this->console instanceof AbstractConsole && $this->console->get('show_help')
                && !isset($this->children[$name])) {
                $this->io->out($this->console->describeCommand($this));

                return $this->postExecute(true);
            }

            try {
                return $this->executeSubCommand($name);
            } catch (CommandNotFoundException $e) {
                $e->getCommand()->renderAlternatives($e->getChild(), $e);

                return $e->getCode();
            } catch (WrongArgumentException $e) {
                $command = $this->getChild($name);

                throw new \RuntimeException(
                    $e->getMessage() . "\n\n[Usage] " . $command->getUsage(),
                    $e->getCode(),
                    $e
                );
            } catch (\Exception $e) {
                throw $e;
            }
        }

        if ($this->handler) {
            if ($this->handler instanceof \Closure) {
                $code = $this->handler;

                return $code($this);
            } elseif (is_callable($this->handler)) {
                return call_user_func($this->handler, $this);
            }
        }

        $result = $this->doExecute();

        return $this->postExecute($result);
    }
1238080
public function execute()
    {
        $success = true;
        foreach ($this->commandList as $command) {
            if (!$this->runSingleCommand($command)) {
                $success = false;
                break;
            }
        }
        return $success;
    }
61509
private function execute() {
        $curlResponse = curl_exec($this->curl);

        $error = $this->getError();
        if (!empty($error)) {
            return $this->curlException($error['error'], $error['error_no']);
        }

        return $curlResponse;
    }
787920
public function run()
    {

        try {
            // register shutdown handler
            register_shutdown_function(array(&$this, "shutdown"));

            // store the actual directory
            $actualDir = getcwd();

            // load the node data with the command information
            $executeNode = $this->jobNode->getExecute();

            // try to load the script from the configuration
            if ($script = $executeNode->getScript()) {
                // change the working directory
                if ($execDir = $executeNode->getDirectory()) {
                    chdir($execDir);
                }

                // check if the configured script is a file
                if (is_file($script) && is_executable($script)) {
                    // initialize the exec params
                    $output = array();
                    $returnVar = 0;

                    // execute the script on the command line
                    exec($executeNode, $output, $returnVar);

                    // restore the old directory
                    if ($execDir && $actualDir) {
                        chdir($actualDir);
                    }

                    // query whether the script has been executed or not
                    if ($returnVar !== 0) {
                        throw new \Exception(implode(PHP_EOL, $output));
                    } else {
                        error_log(implode(PHP_EOL, $output));
                    }

                } else {
                    throw new \Exception(sprintf('Script %s is not a file or not executable', $script));
                }

            } else {
                throw new \Exception(sprintf('Can\t find a script configured in job', $this->jobNode->getName()));
            }

        } catch (\Exception $e) {
            // restore the old directory
            chdir($actualDir);
            // log the exception
            error_log($e->__toString());
        }
    }
536882
private function execute()
    {
        $this->connect();
        try {
            $this->getSyntax();
            $this->command->execute();

            if (preg_match('/^(SELECT|SHOW) /i', $this->select))
                $this->result = $this->command->fetchAll();

        } catch (\PDOException $e) {
            $this->result = "<b>Erro ao Executar Comando: </b> {$e->getMessage()}";
            $this->erro = "<b>Erro ao Executar Comando</b> {$e->getMessage()}";
        }

        parent::setDefault();
    }
352063
public function exec(): int
    {

        $output = [];
        $currentDir = getcwd();
        $returnValue = -1;

        $command = $currentDir . "/bin/box.phar compile";

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

        if ($returnValue != 0) {
            throw new \Exception("Error while generating phar: $returnValue");
        }

        return $returnValue;

    }
853383
protected function prepareExecute()
    {
        if (!($this->console instanceof Console\AbstractConsole)) {
            throw new \Exception('RootCommand::$app should have Console Application');
        }

        if (!$this->getOption('ansi') || strtolower($this->getOption('ansi')) === 'off') {
            $this->console->set('ansi', false);

            $this->io->useColor(false);
        }

        if ($this->getOption('quiet')) {
            $this->console->set('quiet', true);
        }

        if ($this->getOption('verbose')) {
            $this->console->set('verbose', true);
        }

        if ($this->getOption('help')) {
            $this->console->set('show_help', true);
        }
    }
57945
public function run() {
    $this->setupExecution();
    if (empty($this->exec)) {
      throw new TaskException($this, 'You must add at least one command');
    }

    // Set $input to NULL so that it is not inherited by the process.
    $this->setInput(NULL);

    // If 'stopOnFail' is not set, or if there is only one command to run,
    // then execute the single command to run.
    if (!$this->stopOnFail || (count($this->exec) == 1)) {
      return $this->executeCommand($this->getCommand());
    }

    // When executing multiple commands in 'stopOnFail' mode, run them
    // one at a time so that the result will have the exact command
    // that failed available to the caller. This is at the expense of
    // losing the output from all successful commands.
    $data = [];
    $message = '';
    $result = NULL;
    foreach ($this->exec as $command) {
      $result = $this->executeCommand($command);
      $result->accumulateExecutionTime($data);
      $message = $result->accumulateMessage($message);
      $data = $result->mergeData($data);
      if (!$result->wasSuccessful()) {
        return $result;
      }
    }

    return $result;
  }