# \#IP1 Python custom\_exe command not found

**URL:** <https://forum.codecrafters.io/t/ip1-python-custom-exe-command-not-found/4319>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [January 19, 2025, 8:28am UTC](https://forum.codecrafters.io/t/ip1-python-custom-exe-command-not-found/4319 "2025-01-19T08:28:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![microwavestine](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/microwavestine/32/4371_2.png) [@microwavestine](https://forum.codecrafters.io/u/microwavestine)\
**Post date:** [January 19, 2025, 8:28am UTC](https://forum.codecrafters.io/t/ip1-python-custom-exe-command-not-found/4319/1 "2025-01-19T08:28:22Z")

</div>

I’ve tried copy pasting a solution from code example for sanity check, but even with passed solution I get following error when I git push:

```auto
remote: 
remote: [compile] Moved ./.codecrafters/run.sh → ./your_program.sh
remote: [compile] Compilation successful.
remote: 
remote: Debug = true
remote: 
remote: [tester::#IP1] Running tests for Stage #IP1 (Run a program)
remote: [tester::#IP1] [setup] export PATH=/tmp/baz:$PATH
remote: [tester::#IP1] [setup] Available executables:
remote: [tester::#IP1] [setup] - custom_exe_3223
remote: [tester::#IP1] Running ./your_program.sh
remote: [your-program] $ custom_exe_3223 Maria
remote: [your-program] custom_exe_3223: command not found
remote: [tester::#IP1] Output does not match expected value.
remote: [tester::#IP1] Expected: "Program was passed 2 args (including program name)."
remote: [tester::#IP1] Received: "custom_exe_3223: command not found"
remote: [your-program] $ 
remote: [tester::#IP1] Assertion failed.
remote: [tester::#IP1] Test failed
remote: 
remote: Try our CLI to run tests faster without Git: https://codecrafters.io/cli
remote: 
remote: View our article on debugging test failures: https://codecrafters.io/debug
remote: 
To https://git.codecrafters.io/97c45f09a2edc441
   6d619bf..683fa4e master -> master

```

---

<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 19, 2025, 9:32am UTC](https://forum.codecrafters.io/t/ip1-python-custom-exe-command-not-found/4319/2 "2025-01-19T09:32:28Z")

</div>

Hi @microwavestine, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![microwavestine](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/microwavestine/32/4371_2.png) [@microwavestine](https://forum.codecrafters.io/u/microwavestine)\
**Post date:** [January 19, 2025, 12:12pm UTC](https://forum.codecrafters.io/t/ip1-python-custom-exe-command-not-found/4319/3 "2025-01-19T12:12:18Z")

</div>

I’ve published it here [https://github.com/microwavestine/codecrafters-shell-python](https://github.com/microwavestine/codecrafters-shell-python)

I’ve also tried the following code (will delete later):

```auto
import sys
import os
def find_in_path(param):
    path = os.environ['PATH']
    print("Path: " + path)
    print(f"Param: {param}")
    for directory in path.split(":"):
        for (dirpath, dirnames, filenames) in os.walk(directory):
            if param in filenames:
                return f"{dirpath}/{param}"
    return None
def main():
    while True:
        sys.stdout.write("$ ")
        sys.stdout.flush()
        # Wait for user input
        command = input()
        match command.split(" "):
            case ["exit", "0"]:
                exit(0)
            case ["echo", *cmd]:
                print(" ".join(cmd))
            case ["type", *cmd]:
                match cmd:
                    case ["echo" | "exit" | "type"]:
                        print(f"${cmd[0]} is a shell builtin")
                    case _:
                        location = find_in_path(cmd[0])
                        if location:
                            print(f"${cmd[0]} is {location}")
                        else:
                            print(f"${" ".join(cmd)} not found")
            case _:
                if os.path.isfile(command.split(" ")[0]):
                    os.system(command)
                else:
                    print(f"{command}: command not found")
if __name__ == " __main__":
    main()

```

---

<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 20, 2025, 6:48pm UTC](https://forum.codecrafters.io/t/ip1-python-custom-exe-command-not-found/4319/5 "2025-01-20T18:48:36Z")

</div>

Hi @microwavestine, the bug is here:

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

It does not work because `os.path.isfile` tests whether a **path** is a regular file, so you need to pass in a **path** rather than `command.split(" ")[0]`.

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

For example, try something like this instead:

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

---

<div class="post-metadata">

**Author:** ![microwavestine](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/microwavestine/32/4371_2.png) [@microwavestine](https://forum.codecrafters.io/u/microwavestine)\
**Post date:** [January 21, 2025, 2:30pm UTC](https://forum.codecrafters.io/t/ip1-python-custom-exe-command-not-found/4319/7 "2025-01-21T14:30:35Z")

</div>

I found a similar issue here, [(Rust) "Build your own shell" - Stage Run a program #IP1 always fails despite working before - #3 by omagdy7](https://forum.codecrafters.io/t/rust-build-your-own-shell-stage-run-a-program-ip1-always-fails-despite-working-before/3507/3)

And found a hint from this [repo](https://github.com/nobleknightt/codecrafters-shell-python/blob/master/app/main.py) to solve it 😅

---

<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 26, 2025, 2:30pm UTC](https://forum.codecrafters.io/t/ip1-python-custom-exe-command-not-found/4319/8 "2025-01-26T14:30:44Z")

</div>

Closed on January 26, 2025, 2:30pm UTC

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