diff --git a/components/console/introduction.rst b/components/console/introduction.rst index d698af4a96c..fbe41f25a41 100644 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -476,6 +476,8 @@ method:: You can also test a whole console application by using :class:`Symfony\\Component\\Console\\Tester\\ApplicationTester`. +.. _calling-existing-command: + Calling an Existing Command --------------------------- @@ -505,16 +507,27 @@ Calling a command from another one is straightforward:: } First, you :method:`Symfony\\Component\\Console\\Application::find` the -command you want to execute by passing the command name. - -Then, you need to create a new -:class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the arguments and -options you want to pass to the command. +command you want to execute by passing the command name. Then, you need to create +a new :class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the arguments +and options you want to pass to the command. Eventually, calling the ``run()`` method actually executes the command and returns the returned code from the command (return value from command's ``execute()`` method). +.. tip:: + + If you want to suppress the output of the executed command, pass a + :class:`Symfony\\Component\\Console\\Output\\NullOutput` as the second + argument to ``$command->execute()``. + +.. caution:: + + Note that all the commands will run in the same process and some of Symfony's + built-in commands may not work well this way. For instance, the ``cache:clear`` + and ``cache:warmup`` commands change some class definitions, so running + something after them is likely to break. + .. note:: Most of the time, calling a command from code that is not executed on the diff --git a/cookbook/console/console_command.rst b/cookbook/console/console_command.rst index b71b0792781..b48a6c24523 100644 --- a/cookbook/console/console_command.rst +++ b/cookbook/console/console_command.rst @@ -146,6 +146,12 @@ before translating contents:: However for other services the solution might be more complex. For more details, see :doc:`/cookbook/service_container/scopes`. +Invoking other Commands +----------------------- + +See :ref:`calling-existing-command` if you need to implement a command that runs +other dependent commands. + Testing Commands ----------------