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;
+ // 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);
}
/**