function drush_dispatch

8.0.x drush_dispatch($command, $arguments = array())
6.x drush_dispatch($command, $arguments = array())
7.x drush_dispatch($command, $arguments = array())
3.x drush_dispatch($command = NULL)
4.x drush_dispatch($command, $arguments = array())
5.x drush_dispatch($command, $arguments = array())
master drush_dispatch($command, $arguments = array())

Given a command record, dispatch it as if it were the original command. Executes in the currently bootstrapped site using the current option contexts. Note that drush_dispatch will not bootstrap any further than the current command has already bootstrapped; therefore, you should only invoke commands that have the same (or lower) bootstrap requirements.


command: A full $command such as returned by drush_get_commands(), or a string containing the name of the command record from drush_get_commands() to call.

arguments: An array of argument values.

See also


Related topics

3 calls to drush_dispatch()
BaseBoot::bootstrap_and_dispatch in lib/Drush/Boot/BaseBoot.php
Main entrypoint to bootstrap the selected CMS and execute the selected command.
drush_invoke in includes/
Invokes a Drush API call, including all hooks.
drush_topic_core_topic in commands/core/
A command callback.


includes/, line 150
The drush command engine.


function drush_dispatch($command, $arguments = array()) {
  $return = FALSE;

  if ($command) {
    // Add arguments, if this has not already been done.
    // (If the command was fetched from drush_parse_command,
    // then you cannot provide arguments to drush_dispatch.)
    if (empty($command['arguments'])) {
      _drush_prepare_command($command, $arguments);

    // Add command-specific options, if applicable.

    // Test to see if any of the options in the 'cli' context
    // are not represented in the command structure.
    if ((_drush_verify_cli_options($command) === FALSE) || (_drush_verify_cli_arguments($command) === FALSE)) {
      return FALSE;

    // Give command files an opportunity to alter the command record
    drush_command_invoke_all_ref('drush_command_alter', $command);

    // Include and validate command engines.
    if (drush_load_command_engines($command) === FALSE) {
      return FALSE;

    // Do tilde expansion immediately prior to execution,
    // so that tildes are passed through unchanged for
    // remote commands and other redispatches.

    // Call the callback function of the active command.
    $return = call_user_func_array($command['callback'], $command['arguments']);

  // Add a final log entry, just so a timestamp appears.
  drush_log(dt('Command dispatch complete'), LogLevel::NOTICE);

  return $return;