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 1286
Core drush commands.

Code

function drush_core_execute() {
  $result = TRUE;
  $escape = drush_get_option('escape', TRUE);
  // Get all of the args and options that appear after the command name.
  $args = drush_get_original_cli_args_and_options();
  if ($escape) {
    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 we selected a Drupal site, then cwd to the site root prior to exec
  $cwd = FALSE;
  if ($selected_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT')) {
    if (is_dir($selected_root)) {
      $cwd = getcwd();
      drush_op('chdir', $selected_root);
    }
  }
  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);
  }
  // Restore the cwd if we changed it
  if ($cwd) {
    drush_op('chdir', $selected_root);
  }
  if (!$result) {
    return drush_set_error('CORE_EXECUTE_FAILED', dt("Command !command failed.", array('!command' => $cmd)));
  }
  return $result;
}