function drush_backend_parse_output

8.0.x backend.inc drush_backend_parse_output($string, $backend_options = array(), $outputted = FALSE)
6.x backend.inc drush_backend_parse_output($string, $backend_options = array(), $outputted = FALSE)
7.x backend.inc drush_backend_parse_output($string, $backend_options = array(), $outputted = FALSE)
3.x backend.inc drush_backend_parse_output($string, $integrate = TRUE)
4.x backend.inc drush_backend_parse_output($string, $integrate = TRUE)
5.x backend.inc drush_backend_parse_output($string, $backend_options = array(), $outputted = FALSE)
master backend.inc drush_backend_parse_output($string, $backend_options = array(), $outputted = FALSE)

Parse output returned from a Drush command.

Parameters

string: The output of a drush command

integrate: Integrate the errors and log messages from the command into the current process.

Return value

An associative array containing the data from the external command, or the string parameter if it could not be parsed successfully.

1 call to drush_backend_parse_output()
_drush_backend_invoke in includes/backend.inc
Create a new pipe with proc_open, and attempt to parse the output.

File

includes/backend.inc, line 106
Drush backend API

Code

function drush_backend_parse_output($string, $integrate = TRUE) {
  $regex = sprintf(DRUSH_BACKEND_OUTPUT_DELIMITER, '(.*)');

  preg_match("/$regex/s", $string, $match);

  if ($match[1]) {
    // we have our JSON encoded string
    $output = $match[1];
    // remove the match we just made and any non printing characters
    $string = trim(str_replace(sprintf(DRUSH_BACKEND_OUTPUT_DELIMITER, $match[1]), '', $string));
  }

  if ($output) {
    $data = json_decode($output, TRUE);
    if (is_array($data)) {
      if ($integrate) {
        _drush_backend_integrate($data);
      }
      return $data;
    }
  }
  return $string;
}