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.

outputted: Whether output has already been handled.

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 245
Drush backend API

Code

function drush_backend_parse_output($string, $backend_options = array(), $outputted = FALSE) {
  $regex = sprintf(DRUSH_BACKEND_OUTPUT_DELIMITER, '(.*)');

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

  if (!empty($match) && $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 (!empty($output)) {
    $data = json_decode($output, TRUE);
    if (is_array($data)) {
      _drush_backend_integrate($data, $backend_options, $outputted);
      return $data;
    }
  }
  return $string;
}