# Dual-command pipeline #BR6 Rust

**URL:** <https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [November 4, 2025, 5:26pm UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490 "2025-11-04T17:26:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![feamcor](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/feamcor/32/19102_2.png) [@feamcor](https://forum.codecrafters.io/u/feamcor)\
**Post date:** [November 4, 2025, 5:26pm UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/1 "2025-11-04T17:26:20Z")

</div>

I’m stuck on Stage #BR6.

Here are my logs:

```bash
❯ codecrafters test
Initiating test run...

⚡ This is a turbo test run. https://codecrafters.io/turbo

Running tests on your code. Logs should appear shortly...

[compile] Compiling codecrafters-shell v0.1.0 (/app)
[compile] Finished `release` profile [optimized] target(s) in 2.03s
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.

Debug = true

[tester::#BR6] Running tests for Stage #BR6 (Pipelines - Dual-command pipeline)
[tester::#BR6] [setup] export PATH=/tmp/apple/raspberry/orange:$PATH
[tester::#BR6] Running ./your_program.sh
[tester::#BR6] [setup] echo "blueberry grape\napple mango\npineapple raspberry\npear banana\norange strawberry" > "/tmp/qux/file-67"
[your-program] $ cat /tmp/qux/file-67 | wc
[your-program] 5 10 78
[tester::#BR6] ✓ Received expected response
[tester::#BR6] [setup] echo "1. orange strawberry\n2. grape apple\n3. pear blueberry" > "/tmp/foo/file-53"
[your-program] $ tail -f /tmp/foo/file-53 | head -n 5
[tester::#BR6] Didn't find expected line.
[tester::#BR6] Expected: "1. orange strawberry"
[tester::#BR6] Received: "" (no line received)
[tester::#BR6] Assertion failed.
[tester::#BR6] Test failed

View our article on debugging test failures: https://codecrafters.io/debug

```

And here’s a snippet of my code:

```rust
        _ => {
            if pipeline_length == 1 {
                // there is only one command in the pipeline
                run_executable(
                    &command,
                    arguments,
                    Stdio::null(),
                    parsed_command.stdout,
                    parsed_command.stderr,
                    None,
                )
                .expect("TODO: panic message");
            } else if index == 0 {
                // first command in the pipeline
                let mut child = Command::new(&command)
                    .args(arguments.map(|(_, argument)| argument))
                    .stdin(Stdio::null())
                    .stdout(Stdio::piped())
                    .spawn()?;
                previous_output = child.stdout.take();
                previous_child = Some(child);
            } else if index < pipeline_length - 1 {
                // middle command in the pipeline
                let mut child = Command::new(&command)
                    .args(arguments.map(|(_, argument)| argument))
                    .stdin(Stdio::from(previous_output.take().unwrap()))
                    .stdout(Stdio::piped())
                    .spawn()?;
                previous_child.take().unwrap().wait()?;
                previous_output = child.stdout.take();
                previous_child = Some(child);
            } else {
                // last command in the pipeline
                run_executable(
                    &command,
                    arguments,
                    Stdio::from(previous_output.take().unwrap()),
                    parsed_command.stdout,
                    parsed_command.stderr,
                    previous_child.take(),
                )
                .expect("TODO: panic message");
            }
        }

```

See full code at: [codecrafters-shell-rust/src/main.rs at 19502199cf7255da52f6ca6380f28ffe93af7e7e · feamcor/codecrafters-shell-rust · GitHub](https://github.com/feamcor/codecrafters-shell-rust/blob/19502199cf7255da52f6ca6380f28ffe93af7e7e/src/main.rs#L197)

I tried to test from command line and was able to succeed by appending extra lines in the tailed file from another terminal window, but the automated test doesn’t work.

Also, it is not clear if automated testing is expecting `\n` and `\t` inside a double-quoted string to be escaped, or not.

I implemented the escaping but it ends up failing previous tests. See code at [codecrafters-shell-rust/src/main.rs at 19502199cf7255da52f6ca6380f28ffe93af7e7e · feamcor/codecrafters-shell-rust · GitHub](https://github.com/feamcor/codecrafters-shell-rust/blob/19502199cf7255da52f6ca6380f28ffe93af7e7e/src/main.rs#L486)

The reason I ask is because commands like the one below won’t append multiple lines to the file, but just one with literal `\n`.

```bash
echo "1. orange strawberry\n2. grape apple\n3. pear blueberry" > "/tmp/foo/file-53"

```

BTW, `echo` is built-in, so I checked the shell behavior versus bash behavior and I get the same (i.e., just one line).

```bash
❯ echo "1. orange strawberry\n2. grape apple\n3. pear blueberry" > "test"

❯ cat test
1. orange strawberry\n2. grape apple\n3. pear blueberry

❯ cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/codecrafters-shell`
$ echo "1. orange strawberry\n2. grape apple\n3. pear blueberry" > "test2"
$ cat test2
1. orange strawberry\n2. grape apple\n3. pear blueberry
$ exit

❯ cat test2
1. orange strawberry\n2. grape apple\n3. pear blueberry

```

Please advise.  
Thanks.

---

<div class="post-metadata">

**Author:** ![feamcor](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/feamcor/32/19102_2.png) [@feamcor](https://forum.codecrafters.io/u/feamcor)\
**Post date:** [November 5, 2025, 12:06am UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/4 "2025-11-05T00:06:01Z")

</div>

I updated the code to handle `\n` and `\t` when between double quotes for an echo command.  
Anyway, problem with #BR6 persists.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [November 5, 2025, 1:52am UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/5 "2025-11-05T01:52:23Z")

</div>

Hey @feamcor, thanks for the detailed report and all the context. Super helpful!

The test files are meant to contain actual newlines, not the literal string `"\n"`.

We should’ve shown the echo commands with the `-e` flag, like this:

```auto
echo -e "1. orange strawberry\n2. grape apple\n3. pear blueberry" > "/tmp/foo/file-53"

```

We’re addressing the display issue in [this PR](https://github.com/codecrafters-io/shell-tester/pull/167) to make the behavior clearer.

BTW you don’t need to specifically handle \n or \t inside double quotes for echo commands, since these echo commands are there to show how the files are set up by the tester itself.

---

<div class="post-metadata">

**Author:** ![feamcor](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/feamcor/32/19102_2.png) [@feamcor](https://forum.codecrafters.io/u/feamcor)\
**Post date:** [November 5, 2025, 12:22pm UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/6 "2025-11-05T12:22:38Z")

</div>

Hi @andy1li, `echo` is built-in and I don’t remember the implementation of `-e` or any other feature flag on previous tasks. I will change my code to implement it, but maybe the task to implement `echo` should be extended also. Thanks.

---

<div class="post-metadata">

**Author:** ![feamcor](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/feamcor/32/19102_2.png) [@feamcor](https://forum.codecrafters.io/u/feamcor)\
**Post date:** [November 5, 2025, 1:32pm UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/7 "2025-11-05T13:32:47Z")

</div>

Please let me know in case you have any clue of why the test doesn’t succeed.  
I’ll keep trying, but I’m stuck there for a couple of days already.  
Thanks.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [November 6, 2025, 10:54am UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/8 "2025-11-06T10:54:27Z")

</div>

@feamcor Looks like `tail -f` isn’t being executable properly.

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/f/2/f23f78a4a431d6e9fd36032eced232d0724640fe.png)

The output only appears after I press Ctrl+C:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/1/8/18d34da479c5563fe30f99a3876ca1595516d3ee.png)

Whereas in a real shell, it shows up immediately:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/1/7/17a854208c847d05b1775dca826e8443af1202d6.png)

Let me know if you’d like me to dig into this further.

---

<div class="post-metadata">

**Author:** ![feamcor](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/feamcor/32/19102_2.png) [@feamcor](https://forum.codecrafters.io/u/feamcor)\
**Post date:** [November 6, 2025, 11:27am UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/10 "2025-11-06T11:27:30Z")

</div>

Hi @andy1li , don’t worry, I will figure out what I’m doing wrong when using Command for a command like `tail -f`. Thanks.

---

<div class="post-metadata">

**Author:** ![feamcor](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/feamcor/32/19102_2.png) [@feamcor](https://forum.codecrafters.io/u/feamcor)\
**Post date:** [November 6, 2025, 11:56am UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/11 "2025-11-06T11:56:39Z")

</div>

Finally the issue is fixed 🥳

You can see the changes at [codecrafters submit [skip ci] · feamcor/codecrafters-shell-rust@548fd62 · GitHub](https://github.com/feamcor/codecrafters-shell-rust/commit/548fd6216a158dc76d49b96d02da7524e916cae5)

Issue was between the use of `.spawn()` or `.output()` when a command is inheriting the stdout and stderr. I had to branch the command execution if stdout or stderr are being redirected to a file or inherited from parent process.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [November 11, 2025, 11:56am UTC](https://forum.codecrafters.io/t/dual-command-pipeline-br6-rust/15490/12 "2025-11-11T11:56:52Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
