From 583b7b18210124eaed992c7f47cb34fda1133210 Mon Sep 17 00:00:00 2001 From: ZetaNumbers Date: Fri, 15 Apr 2022 15:03:16 +0300 Subject: [PATCH] fix: reduce command have not redirected block's evaluation output (#5193) fixes https://github.com/nushell/nushell/issues/5190 --- crates/nu-command/src/filters/reduce.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/filters/reduce.rs b/crates/nu-command/src/filters/reduce.rs index 5725faf5a1..702961f769 100644 --- a/crates/nu-command/src/filters/reduce.rs +++ b/crates/nu-command/src/filters/reduce.rs @@ -129,7 +129,8 @@ impl Command for Reduce { let mut acc = start_val; - for (idx, x) in input_iter.enumerate() { + let mut input_iter = input_iter.enumerate().peekable(); + while let Some((idx, x)) = input_iter.next() { stack.with_env(&orig_env_vars, &orig_env_hidden); // if the acc coming from previous iter is indexed, drop the index acc = if let Value::Record { cols, vals, .. } = &acc { @@ -178,7 +179,8 @@ impl Command for Reduce { &mut stack, block, PipelineData::new(span), - redirect_stdout, + // redirect stdout until its the last input value + redirect_stdout || input_iter.peek().is_some(), redirect_stderr, )? .into_value(span);