function _drush_backend_invoke

8.0.x _drush_backend_invoke($cmds, $common_backend_options = array(), $context = NULL)
6.x _drush_backend_invoke($cmds, $common_backend_options = array(), $context = NULL)
7.x _drush_backend_invoke($cmds, $common_backend_options = array(), $context = NULL)
3.x _drush_backend_invoke($cmd, $data = null, $integrate = TRUE)
4.x _drush_backend_invoke($cmd, $data = null, $integrate = TRUE)
5.x _drush_backend_invoke($cmds, $common_backend_options = array(), $context = NULL)
master _drush_backend_invoke($cmds, $common_backend_options = array(), $context = NULL)

Create a new pipe with proc_open, and attempt to parse the output.

We use proc_open instead of exec or others because proc_open is best for doing bi-directional pipes, and we need to pass data over STDIN to the remote script.

Exec also seems to exhibit some strangeness in keeping the returned data intact, in that it modifies the newline characters.


cmd: The complete command line call to use.

post_options: An associative array to json-encode and pass to the remote script on stdin.

backend_options: Options for the invocation.

Return value

If the command could not be completed successfully, FALSE. If one command was executed, this will return an associative array containing the data from drush_backend_output(). If multiple commands were executed, this will return an associative array containing one item, 'concurrent', which will contain a list of the different backend invoke results from each concurrent command.

1 call to _drush_backend_invoke()
drush_backend_invoke_concurrent in includes/
Execute a new local or remote command in a new process.


includes/, line 975
Drush backend API


function _drush_backend_invoke($cmds, $common_backend_options = array(), $context = NULL) {
  if (drush_get_context('DRUSH_SIMULATE') && !array_key_exists('override-simulated', $common_backend_options)) {
    foreach ($cmds as $cmd) {
      drush_print(dt('Simulating backend invoke: !cmd', array('!cmd' => $cmd['cmd'])));
    return FALSE;
  foreach ($cmds as $cmd) {
    drush_log(dt('Backend invoke: !cmd', array('!cmd' => $cmd['cmd'])), 'command');
  if (array_key_exists('interactive', $common_backend_options) || array_key_exists('fork', $common_backend_options)) {
    foreach ($cmds as $cmd) {
      $exec_cmd = $cmd['cmd'];
      if (array_key_exists('fork', $common_backend_options)) {
        $exec_cmd .= ' --quiet &';
      drush_log(dt("executing !cmd", array('!cmd' => $exec_cmd)));
      $ret = drush_shell_proc_open($exec_cmd);
    return $ret;
  else {
    $process_limit = drush_get_option_override($common_backend_options, 'concurrency', 1);
    $procs = _drush_backend_proc_open($cmds, $process_limit, $context);
    $procs = is_array($procs) ? $procs : array($procs);

    $ret = array();
    foreach ($procs as $site => $proc) {
      if (($proc['code'] == DRUSH_APPLICATION_ERROR) && isset($common_backend_options['integrate'])) {
        drush_set_error('DRUSH_APPLICATION_ERROR', dt("The external command could not be executed due to an application error."));

      if ($proc['output']) {
        $values = drush_backend_parse_output($proc['output'], $proc['backend-options'], $proc['outputted']);
        $values['site'] = $site;
        if (is_array($values)) {
          if (empty($ret)) {
            $ret = $values;
          elseif (!array_key_exists('concurrent', $ret)) {
            $ret = array('concurrent' => array($ret, $values));
          else {
            $ret['concurrent'][] = $values;
        else {
          $ret = drush_set_error('DRUSH_FRAMEWORK_ERROR', dt("The command could not be executed successfully (returned: !return, code: !code)", array("!return" => $proc['output'], "!code" => $proc['code'])));
  return empty($ret) ? FALSE : $ret;