diff --git a/crates/nu-protocol/src/pipeline_data.rs b/crates/nu-protocol/src/pipeline_data.rs index 72bf48be64..21126e709a 100644 --- a/crates/nu-protocol/src/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline_data.rs @@ -4,9 +4,9 @@ use crate::{ format_error, Config, ListStream, RawStream, ShellError, Span, Value, }; use nu_utils::{stderr_write_all_and_flush, stdout_write_all_and_flush}; -use std::path::PathBuf; use std::sync::{atomic::AtomicBool, Arc}; use std::thread; +use std::{io::Write, path::PathBuf}; const LINE_ENDING_PATTERN: &[char] = &['\r', '\n']; @@ -846,13 +846,29 @@ pub fn print_if_stream( to_stderr: bool, exit_code: Option, ) -> Result { - // NOTE: currently we don't need anything from stderr - // so we just consume and throw away `stderr_stream` to make sure the pipe doesn't fill up - if let Some(stderr_stream) = stderr_stream { + // Write stderr to our stderr, if it's present thread::Builder::new() .name("stderr consumer".to_string()) - .spawn(move || stderr_stream.into_bytes()) + .spawn(move || { + let RawStream { + stream, + leftover, + ctrlc, + .. + } = stderr_stream; + let mut stderr = std::io::stderr(); + let _ = stderr.write_all(&leftover); + drop(leftover); + for bytes in stream { + if nu_utils::ctrl_c::was_pressed(&ctrlc) { + break; + } + if let Ok(bytes) = bytes { + let _ = stderr.write_all(&bytes); + } + } + }) .expect("could not create thread"); }