title: Console/Symfony Call command from controller
body: <p>I have some issues with <strong>Console</strong> when I try to call a Command from a Controller.
  I found a way in the <strong>Symfony CookBook</strong> :
  <a href="http://symfony.com/doc/current/cookbook/console/command_in_controller.html" rel="noreferrer">http://symfony.com/doc/current/cookbook/console/command_in_controller.html</a></p>
  
  <p>It seems doesn't work... Maybe I forgot something!</p>
  
  <h3>Command :</h3>
  
  <pre><code>namespace AppBundle\Command;
  
  use Symfony\Component\Console\Command\Command;
  use Symfony\Component\Console\Input\InputArgument;
  use Symfony\Component\Console\Input\InputInterface;
  use Symfony\Component\Console\Input\InputOption;
  use Symfony\Component\Console\Output\OutputInterface;
  
  class GreetCommand extends Command
  {
      protected function configure()
      {
          $this
              -&gt;setName('demo:greet')
              -&gt;setDescription('Greet someone')
              -&gt;addArgument(
                  'name',
                  InputArgument::OPTIONAL,
                  'Who do you want to greet?'
              )
              -&gt;addOption(
                  'yell',
                  null,
                  InputOption::VALUE_NONE,
                  'If set, the task will yell in uppercase letters'
              )
          ;
      }
  
      protected function execute(InputInterface $input, OutputInterface $output)
      {
          $name = $input-&gt;getArgument('name');
          if ($name) {
              $text = 'Hello '.$name;
          } else {
              $text = 'Hello';
          }
  
          if ($input-&gt;getOption('yell')) {
              $text = strtoupper($text);
          }
  
          $output-&gt;writeln($text);
      }
  }
  </code></pre>
  
  <p>(The command works well in cmd)</p>
  
  <h3>Controller :</h3>
  
  <pre><code>namespace AppBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\Console\Application;
  use Symfony\Component\Console\Input\ArrayInput;
  use Symfony\Component\Console\Output\BufferedOutput;
  
  
  class MainController extends Controller
  {
      public function indexAction()
      {
          $kernel = $this-&gt;get('kernel');
          $application = new Application($kernel);
          $application-&gt;setAutoExit(false);
  
          $input = new ArrayInput(array(
              'command' =&gt; 'demo:greet'
          ));
  
          $output = new BufferedOutput();
          $application-&gt;run($input, $output);
  
          $content = $output-&gt;fetch();
  
          dump($content);die;
      }
  }
  </code></pre>
  
  <h3>Response</h3>
  
  <pre><code>[Symfony\Component\Console\Exception\CommandNotFoundException] There are no commands defined in the "demo" namespace. 
  </code></pre>
  
  <p>Thank you in advance for your help.</p>