function drush_core_execute

8.0.x core.drush.inc drush_core_execute()
6.x core.drush.inc drush_core_execute()
7.x core.drush.inc drush_core_execute()
5.x core.drush.inc drush_core_execute()
master core.drush.inc drush_core_execute()

Command callback. Execute specified shell code. Often used by shell aliases that start with !.

File

commands/core/core.drush.inc, line 1231
Core drush commands.

Code

function drush_core_execute() {
  $result = TRUE;
  // Get all of the args and options that appear after the command name.
  $args = drush_get_original_cli_args_and_options();
  for ($x = 0; $x < count($args); $x++) {
    // escape all args except for command separators.
    if (!in_array($args[$x], array('&&', '||', ';'))) {
      $args[$x] = drush_escapeshellarg($args[$x]);
    }
  }
  $cmd = implode(' ', $args);
  if ($alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS')) {
    $site = drush_sitealias_get_record($alias);
    if (!empty($site['site-list'])) {
      $sites = drush_sitealias_resolve_sitelist($site);
      foreach ($sites as $site_name => $site_spec) {
        $result = _drush_core_execute_cmd($site_spec, $cmd);
        if (!$result) {
          break;
        }
      }
    }
    else {
      $result = _drush_core_execute_cmd($site, $cmd);
    }
  }
  else {
    // Must be a local command.
    $result = (drush_shell_proc_open($cmd) == 0);
  }
  if (!$result) {
    return drush_set_error('CORE_EXECUTE_FAILED', dt("Command !command failed.", array('!command' => $cmd)));
  }
  return $result;
}