# Mismatch between expected and received in JV1

**URL:** <https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [December 28, 2024, 8:31pm UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774 "2024-12-28T20:31:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![akhi3030](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/akhi3030/32/3793_2.png) [@akhi3030](https://forum.codecrafters.io/u/akhi3030)\
**Post date:** [December 28, 2024, 8:31pm UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/1 "2024-12-28T20:31:00Z")

</div>

I’m stuck on Stage #JV1

I believe I have implemented the solution correctly and I see the correct output when I run the test locally. However, I see a different out put when running `codecrafters test` and I cannot explain the difference.

When I run `codecrafters test`, I get:

```auto
remote: [tester::#JV1] Running tests for Stage #JV1 (Redirection - Redirect stdout)
remote: [tester::#JV1] Running ./your_program.sh
remote: [tester::#JV1] Writing file "/tmp/foo/apple" with content "apple"
remote: [tester::#JV1] Writing file "/tmp/foo/grape" with content "grape"
remote: [tester::#JV1] Writing file "/tmp/foo/orange" with content "orange"
remote: [your-program] $ ls /tmp/foo > /tmp/quz/baz.md
remote: [your-program] $ cat /tmp/quz/baz.md
remote: [your-program] apple
remote: [your-program] grape
remote: [your-program] orange
remote: [tester::#JV1] ✓ Received redirected file content
remote: [your-program] $ echo 'Hello Emily' 1> /tmp/quz/qux.md
remote: [your-program] $ cat /tmp/quz/qux.md
remote: [your-program] Hello Emily
remote: [tester::#JV1] ✓ Received redirected file content
remote: [your-program] $ cat /tmp/foo/grape nonexistent 1> /tmp/quz/quz.md
remote: [your-program] /usr/bin/cat: nonexistent: No such file or directory
remote: [tester::#JV1] Output does not match expected value.
remote: [tester::#JV1] Expected: "cat: nonexistent: No such file or directory"
remote: [tester::#JV1] Received: "/usr/bin/cat: nonexistent: No such file or directory"
remote: [your-program] $
remote: [tester::#JV1] Assertion failed.
remote: [tester::#JV1] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

Note the problem is that the difference between the expected and the received output is that in the expected output, the name of the program is `cat` and in the received output, the name of the output is `/usr/bin/cat`.

When I run the test locally, I cannot reproduce the same issue, e.g.:

```auto
➜ codecrafters-shell-rust git:(master) ./your_program.sh
    Finished `release` profile [optimized] target(s) in 0.00s
$ mkdir /tmp/foo
$ echo grape > /tmp/foo/grape
$ cat /tmp/foo/grape
grape
$ cat /tmp/foo/grape nonexistent 1> /tmp/a
cat: nonexistent: No such file or directory

```

And here’s a snippet of my code:

```rust
fn handle_other_command(
    mut stdout: Box<dyn io::Write>,
    mut stderr: Box<dyn io::Write>,
    path: &[String],
    argv0: String,
    argv: &[String],
) {
    match look_in_path(path, &argv0) {
        Some(argv0) => {
            let res = Command::new(argv0).args(argv).output().unwrap();
            let out = String::from_utf8_lossy(&res.stdout);
            let err = String::from_utf8_lossy(&res.stderr);
            write!(stdout, "{}", out).unwrap();
            write!(stderr, "{}", err).unwrap();
        }
        None => writeln!(stdout, "{}: command not found", argv0).unwrap(),
    }
}

```

I am wondering if somehow there is an unexpected difference between the test machine and my local setup and that is causing the problem.

---

<div class="post-metadata">

**Author:** ![akhi3030](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/akhi3030/32/3793_2.png) [@akhi3030](https://forum.codecrafters.io/u/akhi3030)\
**Post date:** [December 28, 2024, 8:36pm UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/2 "2024-12-28T20:36:20Z")

</div>

Published my code in [GitHub - akhi3030/codecrafters-shell-rust](https://github.com/akhi3030/codecrafters-shell-rust).

---

<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:** [December 29, 2024, 7:44pm UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/5 "2024-12-29T19:44:46Z")

</div>

Hi @akhi3030, looks like you’ve got past this stage — do you happen to remember what was wrong? Would love to see if we can improve the tester / instructions.

---

<div class="post-metadata">

**Author:** ![akhi3030](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/akhi3030/32/3793_2.png) [@akhi3030](https://forum.codecrafters.io/u/akhi3030)\
**Post date:** [December 29, 2024, 8:02pm UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/6 "2024-12-29T20:02:50Z")

</div>

Sadly, I couldn’t figure out what the actual problem was and I hacked my way around it. I added the following line to my code:

```rust
            let err = match err.strip_prefix("/usr/bin/") {
                None => err.to_string(),
                Some(res) => res.to_string(),
            };

```

Essentially, if I see the unnecessary `/usr/bin/` in the output, I remove it just to pass the test.

---

<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:** [December 29, 2024, 8:06pm UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/7 "2024-12-29T20:06:54Z")

</div>

Thanks for sharing the details! We’ll look into the issue and keep you updated on any progress.

---

<div class="post-metadata">

**Author:** ![akhi3030](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/akhi3030/32/3793_2.png) [@akhi3030](https://forum.codecrafters.io/u/akhi3030)\
**Post date:** [December 29, 2024, 8:19pm UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/8 "2024-12-29T20:19:36Z")

</div>

Great, thanks for looking into it. If it helps, I am running locally on a mac and haven’t tried running my code on a linux machine.

---

<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:** [January 3, 2025, 9:57pm UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/9 "2025-01-03T21:57:19Z")

</div>

Hi @akhi3030, the issue can be avoided if you run the command directly without using the full path:

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

---

<div class="post-metadata">

**Author:** ![akhi3030](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/akhi3030/32/3793_2.png) [@akhi3030](https://forum.codecrafters.io/u/akhi3030)\
**Post date:** [January 4, 2025, 9:41am UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/11 "2025-01-04T09:41:18Z")

</div>

Hi @andy1li. Thanks for getting back to me. I suppose it is down to some system differences why `look_in_path` is returning different results. But this makes sense.

---

<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:** [January 9, 2025, 9:41am UTC](https://forum.codecrafters.io/t/mismatch-between-expected-and-received-in-jv1/3774/12 "2025-01-09T09:41:33Z")

</div>

Closed on January 9, 2025, 9:41am UTC

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