How to run Drupal console command from code?
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.