protected function doRunCommand(SymfonyCommand $command, InputInterface $input, OutputInterface $output): int
    {
        $this->runningCommand = $command;

        foreach ($command->getHelperSet() as $helper) {
            if ($helper instanceof InputAwareInterface) {
                $helper->setInput($input);
            }
        }

        if ($this->eventManager === null) {
            return $command->run($input, $output);
        }

        // bind before the console.command event, so the listeners have access to input options/arguments
        try {
            $command->mergeApplicationDefinition();
            $input->bind($command->getDefinition());
        } catch (ExceptionInterface $exception) {
            // ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition
        }

        $event     = new ConsoleCommandEvent($command, $input, $output);
        $exception = null;

        try {
            $this->eventManager->trigger($event);

            if ($event->commandShouldRun()) {
                $exitCode = $command->run($input, $output);
            } else {
                $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
            }
        } catch (Throwable $exception) {
            $this->eventManager->trigger($event = new ConsoleErrorEvent($command, $input, $output, $exception));
            $exception = $event->getError();

            if (($exitCode = $event->getExitCode()) === 0) {
                $exception = null;
            }
        }

        $this->eventManager->trigger($event = new ConsoleTerminateEvent($command, $input, $output, $exitCode));

        if ($exception !== null) {
            throw $exception;
        }

        return $event->getExitCode();
    }