@@ -8,13 +8,13 @@ or if you want to create a "meta" command that runs a bunch of other commands
88changed on the production servers: clearing the cache, generating Doctrine
99proxies, dumping web assets, ...).
1010
11- Use the :method: `Symfony\\ Component\\ Console\\ Application::find ` method to
12- find the command you want to run by passing the command name. Then, create a
13- new :class: ` Symfony \\ Component \\ Console \\ Input \\ ArrayInput ` with the
14- arguments and options you want to pass to the command .
11+ Use the :method: `Symfony\\ Component\\ Console\\ Application::doRun `. Then, create
12+ a new :class: ` Symfony \\ Component \\ Console \\ Input \\ ArrayInput ` with the
13+ arguments and options you want to pass to the command. The command name must be
14+ the first argument .
1515
16- Eventually, calling the ``run () `` method actually runs the command and returns
17- the returned code from the command (return value from command's ``execute() ``
16+ Eventually, calling the ``doRun () `` method actually runs the command and returns
17+ the returned code from the command (return value from command ``execute() ``
1818method)::
1919
2020 // ...
@@ -29,15 +29,14 @@ method)::
2929
3030 protected function execute(InputInterface $input, OutputInterface $output): int
3131 {
32- $command = $this->getApplication()->find('demo:greet');
33-
34- $arguments = [
32+ $greetInput = new ArrayInput([
33+ // the command name is passed as first argument
34+ 'command' => 'demo:greet',
3535 'name' => 'Fabien',
3636 '--yell' => true,
37- ];
37+ ]) ;
3838
39- $greetInput = new ArrayInput($arguments);
40- $returnCode = $command->run($greetInput, $output);
39+ $returnCode = $this->getApplication()->doRun($greetInput, $output);
4140
4241 // ...
4342 }
@@ -47,7 +46,16 @@ method)::
4746
4847 If you want to suppress the output of the executed command, pass a
4948 :class: `Symfony\\ Component\\ Console\\ Output\\ NullOutput ` as the second
50- argument to ``$command->run() ``.
49+ argument to ``$application->doRun() ``.
50+
51+ .. note ::
52+
53+ Using ``doRun() `` instead of ``run() `` prevents autoexiting and allows to
54+ return the exit code instead.
55+
56+ Also, using ``$this->getApplication()->doRun() `` instead of
57+ ``$this->getApplication()->find('demo:greet')->run() `` will allow proper
58+ events to be dispatched for that inner command as well.
5159
5260.. caution ::
5361
0 commit comments