From 6a7b17e2a94ddd62ac0dc8f1efcaf09daa30f752 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Sun, 4 Feb 2018 22:03:29 -0800 Subject: [PATCH 1/2] Fixes #3351: Always use 'fwrite' instead of 'print' in 'drush_print' to avoid undesired interaction with PHP's handling of the php headers. --- includes/output.inc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/includes/output.inc b/includes/output.inc index 1c56dc63ef..e3e8f3bd9c 100644 --- a/includes/output.inc +++ b/includes/output.inc @@ -34,12 +34,10 @@ function drush_print($message = '', $indent = 0, $handle = NULL, $newline = TRUE if (($charset = drush_get_option('output_charset')) && function_exists('iconv')) { $msg = iconv('UTF-8', $charset, $msg); } - if (isset($handle)) { - fwrite($handle, $msg); - } - else { - print $msg; + if (!isset($handle)) { + $handle = STDOUT; } + fwrite($handle, $msg); } /** From 02f3775233ffa5582ba11afc8448607ac2444b81 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 5 Feb 2018 08:04:41 -0800 Subject: [PATCH 2/2] Continue to capture output in the backend results. --- includes/output.inc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/output.inc b/includes/output.inc index e3e8f3bd9c..950953f121 100644 --- a/includes/output.inc +++ b/includes/output.inc @@ -36,6 +36,11 @@ function drush_print($message = '', $indent = 0, $handle = NULL, $newline = TRUE } if (!isset($handle)) { $handle = STDOUT; + // In the past, Drush would use `print` here; now that we are using + // fwrite (to avoid problems with php sending the http headers), we + // must explicitly capture the output, because ob_start() / ob_end() + // does not capture output written via fwrite to STDOUT. + drush_backend_output_collect($msg); } fwrite($handle, $msg); }