From f35741d50e02aad6d54ed6ed8afba11175e74442 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Wed, 25 Oct 2023 22:35:51 +0800 Subject: [PATCH] redirection: fix internal commands error with `o+e>` redirection (#10816) # Description Currently the following command is broken: ```nushell echo a o+e> 1.txt ``` It's because we don't redirect output of `echo` command. This pr is trying to fix it. --- .../nu-command/tests/commands/redirection.rs | 10 +++++---- crates/nu-engine/src/eval.rs | 21 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/nu-command/tests/commands/redirection.rs b/crates/nu-command/tests/commands/redirection.rs index 8f121a2f10..8c0f079652 100644 --- a/crates/nu-command/tests/commands/redirection.rs +++ b/crates/nu-command/tests/commands/redirection.rs @@ -216,12 +216,14 @@ fn redirect_support_variable() { assert!(output.out.contains("hello")); - let output = nu!( + nu!( cwd: dirs.test(), - "let x = 'tmp_file'; echo 'hello' out+err> $x; open tmp_file" + "let x = 'tmp_file'; echo 'hello there' out+err> $x; open tmp_file" ); - - assert!(output.out.contains("hello")); + // check for stdout redirection file. + let expected_out_file = dirs.test().join("tmp_file"); + let actual = file_contents(expected_out_file); + assert!(actual.contains("hello there")); }) } diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index f3af6bfcd3..39d9881250 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -925,15 +925,18 @@ fn eval_element_with_input( *is_subexpression, )? } - _ => eval_element_with_input( - engine_state, - stack, - &PipelineElement::Expression(*cmd_span, cmd_exp.clone()), - input, - redirect_stdout, - redirect_stderr, - ) - .map(|x| x.0)?, + _ => { + // we need to redirect output, so the result can be saved and pass to `save` command. + eval_element_with_input( + engine_state, + stack, + &PipelineElement::Expression(*cmd_span, cmd_exp.clone()), + input, + true, + redirect_stderr, + ) + .map(|x| x.0)? + } }; eval_element_with_input( engine_state,