# \[Rust\] Stuck on stage #ei0

**URL:** <https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [January 27, 2025, 8:23pm UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509 "2025-01-27T20:23:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![milongo](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/milongo/32/4297_2.png) [@milongo](https://forum.codecrafters.io/u/milongo)\
**Post date:** [January 27, 2025, 8:23pm UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509/1 "2025-01-27T20:23:53Z")

</div>

I’m stuck on Stage #ei0.

Here are my logs:

```auto
remote: ------------------------------------------------------------------------
remote: 
remote: 
remote: _______ __ _                   
remote: / __\___  __| |___ / __\___  ___ / _|| |____ _ _____ 
remote: / / / _ \ / _` | / _ \ / / | ' __|/ _` || |_ |__ |/ _ \| ' __|/__ |
remote: / /___| (_) || (_| ||__// /___| | | (_| || _|| |_|__/| | \__ 
remote: \ ____/ \___ / \ __,_| \___ |\ ____/|_| \__ ,_||_| \ __|\___ ||_| |___/
remote: 
remote: 
remote: Welcome to CodeCrafters! Your commit was received successfully.
remote: 
remote: ------------------------------------------------------------------------
remote: 
remote: ⚡ This is a turbo test run. https://codecrafters.io/turbo
remote: 
remote: Running tests on your code. Logs should appear shortly...
remote: 
remote: [compile] Compiling codecrafters-shell v0.1.0 (/app)
remote: [compile] Finished `release` profile [optimized] target(s) in 1.22s
remote: [compile] Moved ./.codecrafters/run.sh → ./your_program.sh
remote: [compile] Compilation successful.
remote: 
remote: Debug = true
remote: 
remote: [tester::#EI0] Running tests for Stage #EI0 (Navigation - The pwd builtin)
remote: [tester::#EI0] Running ./your_program.sh
remote: [your-program] $ type pwd
remote: [your-program] pwd is a shell builtin
remote: [tester::#EI0] ✓ Received expected response
remote: [your-program] $ pwd
remote: [your-program] pwd: command not found

```

And here’s a snippet of my code:

```rust

                let output = Command::new(command).args(args).output();

                match output {
                    Ok(output) => {
                        if !output.stdout.is_empty() {
                            print!("{}", String::from_utf8_lossy(&output.stdout));
                        }
                        if !output.stderr.is_empty() {
                            eprint!("{}", String::from_utf8_lossy(&output.stderr));
                        }
                    }
                    Err(_err) => println!("{}: command not found", command),
                }
            }
}

```

I feel like this should (maybe it’s cheating) capture any command and correctly pass it to the shell. Indeed, I get this when running it locally:

```auto
vscode ➜ /workspaces/codecrafters-shell-rust (master) $ ./your_program.sh
    Finished `release` profile [optimized] target(s) in 0.00s
$ type pwd
pwd is a shell builtin
$ pwd
/workspaces/codecrafters-shell-rust
$ 

```

So I’m a little confused how the output on the runner is different?  
I made sure to push. Also, adding the debug flag seems to not have done anything?

---

<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 27, 2025, 8:23pm UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509/2 "2025-01-27T20:23:53Z")

</div>

Hi, thanks for your post!

I’m currently out of the office and will return on Feb 3. I’ll get back to you as soon as possible after I’m back.

---

<div class="post-metadata">

**Author:** ![milongo](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/milongo/32/4297_2.png) [@milongo](https://forum.codecrafters.io/u/milongo)\
**Post date:** [February 6, 2025, 9:15pm UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509/3 "2025-02-06T21:15:17Z")

</div>

Ok so I’m not sure _why_ this fails or how but I figure it may make sense in the context of the challenge to somehow force the user to write the `pwd` as a shell built in. I got past this stage by just coding the behaviour instead of using Command.

---

<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:** [February 7, 2025, 9:00pm UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509/5 "2025-02-07T21:00:40Z")

</div>

Hi @milongo, let’s take another look at how a real shell handles `pwd`. Here’s the output from zsh on my machine:

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

Since `pwd` is a built-in command in most shells, implementing it manually aligns with how real shells work.

* * *

That being said, the `pwd` implementation in most shells is essentially a thin wrapper around the [getcwd](https://man7.org/linux/man-pages/man3/getcwd.3.html) function in **libc** , which itself is a thin wrapper for the `getcwd` syscall provided by the operating system.

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

So while it might feel like cheating, most shells just hand it off to the the operating system as well.

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

---

<div class="post-metadata">

**Author:** ![milongo](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/milongo/32/4297_2.png) [@milongo](https://forum.codecrafters.io/u/milongo)\
**Post date:** [February 8, 2025, 7:28pm UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509/7 "2025-02-08T19:28:06Z")

</div>

What you say makes sense, but I have a couple of things to mention:

I’m not sure it’s 100% clear what is a built-in vs what isn’t. I don’t think that any of the stages’ instructions explained the difference between a built-in and a … _not_-built-in.

My point is that a user could have chosen to implement any of the “built-in” functionalities using Rust’s process execution (`std::process::Command`) and the outputs _should_ have matched (I guess as long as the “shell” the command is launched in has that command available? Not sure how this works), even if the functionality wasn’t implemented as a built-in.

For example, if I comment my “built-in” `echo`, I get this:

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

When doing stage #ei0 I had implemented `pwd` using the `command` as well, but the tests were failing. I spent about 1 hour trying to figure out how the test was failing on the remote runner. I verified the `pwd` binary existed somewhere. I verified it was executable. Only until I actually implemented it as a built-in did it work. It makes sense, for the purposes of the task (which was to _implement_ it as a builtin). But _how_ could you tell the difference? That was killing me.

---

<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:** [February 8, 2025, 8:27pm UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509/8 "2025-02-08T20:27:12Z")

</div>

@milongo Thanks for the thoughtful follow-up questions!

> I’m not sure it’s 100% clear what is a built-in vs what isn’t. I don’t think that any of the stages’ instructions explained the difference between a built-in and a … _not_ -built-in

Good point! The distinction isn’t always absolute, and some command can exist as both built-in and external programs.

Here’s what I get on my machine:

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

* * *

> My point is that a user could have chosen to implement any of the “built-in” functionalities using Rust’s process execution (`std::process::Command` )

You’re absolutely right. This works as long as an external `pwd` exists on the system. It worked on your machine because the external version was present, but on our tester’s system, it seems `pwd` doesn’t exist as an external binary.

* * *

> if I comment my “built-in” `echo`

It’s the same:

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

* * *

> But _how_ could you tell the difference?

A quick way to check is to use `type` or `which` in a real shell.

Let me know if you’d like further clarification!

---

<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:** [March 10, 2025, 9:44am UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509/9 "2025-03-10T09:44:40Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<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:** [March 15, 2025, 9:45am UTC](https://forum.codecrafters.io/t/rust-stuck-on-stage-ei0/4509/10 "2025-03-15T09:45:19Z")

</div>

Closed on March 15, 2025, 9:45am UTC

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