# Rust - \[Shell\] Stuck on #IP1, Error Expected: "Program Signature: 4652645643", Received "$"

**URL:** <https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [June 12, 2025, 10:41am UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019 "2025-06-12T10:41:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rioba-Ian](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rioba-ian/32/12694_2.png) [@Rioba-Ian](https://forum.codecrafters.io/u/Rioba-Ian)\
**Post date:** [June 12, 2025, 10:41am UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019/1 "2025-06-12T10:41:08Z")

</div>

I was expecting the program to execute but it seems it doesn’t execute and thus giving the correct output. In the exec\_external I’m receviving the executable path and then calling it using Command::new(path\_of\_cmd)

I had suspected the arguments are not being passed to cmd and I made sure by giving command mutable so as to check the length and add args to it. When testing with ls -a it works correctly.

The github repo to my code is [GitHub - Rioba-Ian/codecrafters-shell-rust](https://github.com/Rioba-Ian/codecrafters-shell-rust)

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/7/7b854de280ce2a6cca39c1537c5a2cdcc18f221b.jpeg)

I’ll appreciate any thoughts or help. Thanks

---

<div class="post-metadata">

**Author:** ![EshaanAgg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/eshaanagg/32/399_2.png) [@EshaanAgg](https://forum.codecrafters.io/u/EshaanAgg)\
**Post date:** [June 12, 2025, 12:01pm UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019/3 "2025-06-12T12:01:01Z")

</div>

Since you’re using the [`Command`](https://doc.rust-lang.org/std/process/struct.Command.html) in Rust, you can use the [`stdout`](https://doc.rust-lang.org/std/process/struct.Command.html#method.stdout) method on the same to redirect the executed command’s output to the STDOUT stream, which is visible to the user (and the tester).

You would then not need to print the args manually, as the binary itself would take care of printing them. All you need to do is to forward the arguments correctly, and set the streams for output (and optionally error) correctly to match STDOUT (and STDERR).

---

<div class="post-metadata">

**Author:** ![Rioba-Ian](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rioba-ian/32/12694_2.png) [@Rioba-Ian](https://forum.codecrafters.io/u/Rioba-Ian)\
**Post date:** [June 13, 2025, 6:49am UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019/4 "2025-06-13T06:49:26Z")

</div>

I’ve changed how the output comes but I’m either getting an extra space which if I try to just use print!({}, output\_string) won’t remove it.

Thanks a lot for the suggestion, it fixed the output that the test expects. My function now looks as follows

```rust
fn exec_external(cmd: &str, args: &[&str]) {
    println!(
        "Program was passed {} args (including program name).",
        args.len() + 1
    );
    println!("Arg #0 (program name): {}", cmd);

    for (i, arg) in args.iter().enumerate() {
        println!("Arg #{}: {}", i + 1, arg);
    }

    let mut command = Command::new(cmd);

    if args.len() > 1 {
        command.args(args);
    }

    let output = command.output().expect("failed to execute process");

    let output_string = String::from_utf8(output.stdout).expect("Invalid output utf8");

    print!("{}", output_string)
}

```

---

<div class="post-metadata">

**Author:** ![EshaanAgg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/eshaanagg/32/399_2.png) [@EshaanAgg](https://forum.codecrafters.io/u/EshaanAgg)\
**Post date:** [June 13, 2025, 7:53am UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019/5 "2025-06-13T07:53:14Z")

</div>

Yes! This looks like good progress. But actually, two more changes are needed:

- You don’t need to print the debugging information like the argument count and the argument. This would cause the tester to fail assertions, as all of this content would be printed twice (once by your shell, and then by the binary)
- You also need to supply all the `args`, and remove the check `if args.len() > 1` as your arguments are exclusive of the command name.

The final function should be something like:

```rust
fn exec_external(cmd: &str, args: &[&str]) {
    let mut command = Command::new(cmd);

    command.args(args);

    let output = command.output().expect("failed to execute process");
    let output_string = String::from_utf8(output.stdout).expect("Invalid output utf8");

    print!("{}", output_string)
}

```

Also unrelated: The current code fails at the second stage itself. To fix that, you might need to change:

```auto
println!("{:?}: command not found", other);

```

to

```auto
println!("{}: command not found", other);

```

(Removed the debug print so that the command `other` does not appear quoted.)

---

<div class="post-metadata">

**Author:** ![Rioba-Ian](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rioba-ian/32/12694_2.png) [@Rioba-Ian](https://forum.codecrafters.io/u/Rioba-Ian)\
**Post date:** [June 13, 2025, 8:10am UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019/6 "2025-06-13T08:10:49Z")

</div>

I’ve made the adjustments but it looks I’m almost back to the same issues as before. I’ve updated my code on github [GitHub - Rioba-Ian/codecrafters-shell-rust](https://github.com/Rioba-Ian/codecrafters-shell-rust).

Asking LLMs has not been fruitful as it will quickly deviate and go completely opposite of the tests.

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

Thank you for helping.

---

<div class="post-metadata">

**Author:** ![EshaanAgg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/eshaanagg/32/399_2.png) [@EshaanAgg](https://forum.codecrafters.io/u/EshaanAgg)\
**Post date:** [June 13, 2025, 8:23am UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019/7 "2025-06-13T08:23:03Z")

</div>

> [@EshaanAgg](#):
>
> The final function should be something like:
> 
> ```auto
> fn exec_external(cmd: &str, args: &[&str]) {
> let mut command = Command::new(cmd);
> 
> command.args(args);
> 
> let output = command.output().expect("failed to execute process");
> let output_string = String::from_utf8(output.stdout).expect("Invalid output utf8");
> 
> print!("{}", output_string)
> }
> 
> ```

Can you try using this as the `exec_external` function? It’s the same as your current implementation, but does not logs the arguments manually (that is the job of the `custom_exe`).

---

<div class="post-metadata">

**Author:** ![Rioba-Ian](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rioba-ian/32/12694_2.png) [@Rioba-Ian](https://forum.codecrafters.io/u/Rioba-Ian)\
**Post date:** [June 13, 2025, 8:40am UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019/8 "2025-06-13T08:40:57Z")

</div>

Yeah, it worked. I was doing it wrong.

Thanks a lot for the help.

---

<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:** [June 18, 2025, 8:41am UTC](https://forum.codecrafters.io/t/rust-shell-stuck-on-ip1-error-expected-program-signature-4652645643-received/12019/9 "2025-06-18T08:41:55Z")

</div>

Closed on June 18, 2025, 8:41am UTC

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