On Drupal 9.5.11, I wanted to call the command from a contrib module (search_api) to get more control over it. This is how I did :
$self = Drush::aliasManager()->getSelf(); $finished = FALSE; // These are the options of the drush command $options = ['limit' => '100', 'batch-size' => '50']; while (!$finished) { // You can specify an index id in the 3rd argument, ex : ['index'] $process = $this->processManager()->drush($self, 'search-api:index', [], $options); // We capture the output to print it here and check if it finished. $process->run($process->showRealtime()->hideStdout()); if (!$process->isSuccessful() || empty($process->getOutput())) { $finished = TRUE; } else { // \Drupal::logger('YourModule')->notice($process->getOutput(), []); } }
You can check the command drush search-api:index to identify the argument and the options of it, and how there are dealt with in this code.
/vendor/bin/drush/drushseems to be a bit of an odd location for Drush./vendorin your machine's root, really? I bet you just referenced the wrong location.