diff --git a/includes/backend.inc b/includes/backend.inc index 1800bea..f747e64 100644 --- a/includes/backend.inc +++ b/includes/backend.inc @@ -414,37 +414,53 @@ function _drush_backend_proc_open($cmds, $process_limit, $context = NULL) { $info = stream_get_meta_data($current_process['pipes'][1]); if (!feof($current_process['pipes'][1]) && !$info['timed_out']) { + // Read the next 4096 characters from the pipe. $string = fread($current_process['pipes'][1], 4096); + // Does this $string include the start of the end output. $output_end_pos = strpos($string, 'DRUSH_BACKEND_OUTPUT_START>>>'); if ($output_end_pos !== FALSE) { + // Find everything up to the start of the end output. $trailing_string = substr($string, 0, $output_end_pos); + $bucket[$site]['output'] .= $trailing_string; + // And if that's not empty, process it for drush_packets. if (!empty($trailing_string)) { - drush_backend_parse_packets($trailing_string, $bucket[$site]['backend-options']); - _drush_backend_print_output($trailing_string, $bucket[$site]['backend-options']); - $bucket[$site]['outputted'] = TRUE; + drush_backend_parse_packets($bucket[$site]['output'], $bucket[$site]['backend-options']); + _drush_backend_print_output($bucket[$site]['output'], $bucket[$site]['backend-options']); + if (!empty($trailing_string)) { + $bucket[$site]['outputted'] = TRUE; + } } + // Append the start of the output to the output bucket. + $bucket[$site]['output'] .= substr($string, $output_end_pos); + $string = ''; + // Flag this pipe as being at the end of command output, though we + // may still have more of the output to read. $bucket[$site]['end_of_output'] = TRUE; } - if (!$bucket[$site]['end_of_output']) { - drush_backend_parse_packets($string, $bucket[$site]['backend-options']); - // Pass output through. - _drush_backend_print_output($string, $bucket[$site]['backend-options']); - if (!empty($string)) { - $bucket[$site]['outputted'] = TRUE; - } - } $bucket[$site][1] .= $string; $bucket[$site]['output'] .= $string; $info = stream_get_meta_data($current_process['pipes'][1]); + if (!$bucket[$site]['end_of_output']) { + drush_backend_parse_packets($bucket[$site]['output'], $bucket[$site]['backend-options']); + } + flush(); // Reset the $nap_time variable as there might be output to process // next time around: - if (!empty($string)) { + if (!empty($bucket[$site]['output'])) { $nap_time = 0; } } else { + // Pass output through. + if (!$bucket[$site]['end_of_output']) { + _drush_backend_print_output($bucket[$site]['output'], $bucket[$site]['backend-options']); + if (!empty($bucket[$site]['output'])) { + $bucket[$site]['outputted'] = TRUE; + } + flush(); + } fclose($current_process['pipes'][1]); unset($current_process['pipes'][1]); // close the pipe , set a marker