How to run Drupal console command from code? I have found a lot of documentation on how to run Drush commands from code, but I'm specifically looking on how to run a Drupal Console command from code.

I have some experience in Symfony and I know how to run a Symfony command from code. Since a Drupal console command extends on Symfony command, I thought this should be rather easy. Simply following this tutorial doesn't amount to anything though.

I am trying to run a command in a hook_cron() implementation in a custom module.
Run shell commands via the Process class available in the Symfony framework. 

From the Symfony docs:

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

$process = new Process('ls -lsa');
$process-&gt;run();

// executes after the command finishes
if (!$process-&gt;isSuccessful()) {
    throw new ProcessFailedException($process);
}

echo $process-&gt;getOutput();



  The component takes care of the subtle differences between the
  different platforms when executing the command.


Replace the ls -lsa command in the Process() constructor with your Drupal console command.