Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Command.php

function Command::run

Runs the command.

The code to execute is either defined directly with the setCode() method or by overriding the execute() method in a sub-class.

Return value

int The command exit code

Throws

ExceptionInterface When input binding fails. Bypass this by calling {@link ignoreValidationErrors()}.

See also

setCode()

execute()

6 calls to Command::run()
GlobalCommand::run in vendor/composer/composer/src/Composer/Command/GlobalCommand.php
GlobalCommand::run in vendor/composer/composer/src/Composer/Command/GlobalCommand.php
SingleCommandApplication::run in vendor/symfony/console/SingleCommandApplication.php
Runs the command.
SingleCommandApplication::run in vendor/symfony/console/SingleCommandApplication.php
Runs the command.
TraceableCommand::run in vendor/symfony/console/Command/TraceableCommand.php
Runs the command.

... See full list

4 methods override Command::run()
GlobalCommand::run in vendor/composer/composer/src/Composer/Command/GlobalCommand.php
LazyCommand::run in vendor/symfony/console/Command/LazyCommand.php
Runs the command.
SingleCommandApplication::run in vendor/symfony/console/SingleCommandApplication.php
Runs the command.
TraceableCommand::run in vendor/symfony/console/Command/TraceableCommand.php
Runs the command.

File

vendor/symfony/console/Command/Command.php, line 231

Class

Command
Base class for all commands.

Namespace

Symfony\Component\Console\Command

Code

public function run(InputInterface $input, OutputInterface $output) : int {
    // add the application arguments and options
    $this->mergeApplicationDefinition();
    // bind the input against the command specific arguments/options
    try {
        $input->bind($this->getDefinition());
    } catch (ExceptionInterface $e) {
        if (!$this->ignoreValidationErrors) {
            throw $e;
        }
    }
    $this->initialize($input, $output);
    if (null !== $this->processTitle) {
        if (\function_exists('cli_set_process_title')) {
            if (!@cli_set_process_title($this->processTitle)) {
                if ('Darwin' === \PHP_OS) {
                    $output->writeln('<comment>Running "cli_set_process_title" as an unprivileged user is not supported on MacOS.</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE);
                }
                else {
                    cli_set_process_title($this->processTitle);
                }
            }
        }
        elseif (\function_exists('setproctitle')) {
            setproctitle($this->processTitle);
        }
        elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
            $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
        }
    }
    if ($input->isInteractive()) {
        $this->interact($input, $output);
    }
    // The command name argument is often omitted when a command is executed directly with its run() method.
    // It would fail the validation if we didn't make sure the command argument is present,
    // since it's required by the application.
    if ($input->hasArgument('command') && null === $input->getArgument('command')) {
        $input->setArgument('command', $this->getName());
    }
    $input->validate();
    if ($this->code) {
        $statusCode = ($this->code)($input, $output);
    }
    else {
        $statusCode = $this->execute($input, $output);
    }
    return is_numeric($statusCode) ? (int) $statusCode : 0;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal