# Question regarding #MG5

**URL:** https://forum.codecrafters.io/t/question-regarding-mg5/16176
**Category:** Challenges
**Tags:** challenge:shell
**Created:** [June 23, 2026, 8:26pm UTC](https://forum.codecrafters.io/t/question-regarding-mg5/16176 "2026-06-23T20:26:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![HadiSaleemi666](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/hadisaleemi666/32/26929_2.png) [@HadiSaleemi666](https://forum.codecrafters.io/u/HadiSaleemi666)
#### Post date: [June 23, 2026, 8:26pm UTC](https://forum.codecrafters.io/t/question-regarding-mg5/16176/1 "2026-06-23T20:26:27Z")

</div>

Hello, hope everyone’s doing well. I have a question regarding #MG5. I’m currently working on a windows device and I realized after testing that the code requires the answer to be in a posix format? because when I attempt to run my code on my own device it only works if I add the .exe extension, but that means the tests dont pass but without it, the tests do pass.

Here is my entire code:

```python
import sys
import os

def getFirstWordEndIndex(command):
    index = command.find(" ")
    index = index + 1
    return index

def main():
    # TODO: Uncomment the code below to pass the first stage
    builtinCommands = ["echo", "type", "exit"]
    while True:
        sys.stdout.write("$ ")
        command = input()
        index = getFirstWordEndIndex(command)
        if command == "exit":
            break
        elif "echo" in command[:index]:
            print(command[index:])
        elif "type" in command[:index]:
            if command[index:] in builtinCommands:
                print(f"{command[index:]} is a shell builtin")
            else:
                system_path = os.environ.get("PATH")
                command = command[index:]
                directories = system_path.split(os.pathsep)
                found = False
                for directory in directories:
                    if (
                        os.path.exists(directory)
                        and command in os.listdir(directory)
                        and os.access(f"{directory}{os.path.sep}{command}", os.X_OK)
                    ):
                        found = True
                        print(f"{command} is {directory}{os.path.sep}{command}")
                        break
                if not found:
                    print(f"{command}: not found")
        else:
            print(f"{command}: command not found")
   

if __name__ == " __main__":
        main()

```

(Yes I know my code isn’t great lol)

So I suppose my question is, is there a way to generalize it so that it works on any OS? Because im not sure a function exists to figure out the exact extension of an executable for each OS and I figured out how I could use os.pathsep and os.path.sep to get around the different delimeters but beyond that I’m a little lost.

---

<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: [June 23, 2026, 9:11pm UTC](https://forum.codecrafters.io/t/question-regarding-mg5/16176/4 "2026-06-23T21:11:13Z")

</div>

Hey @HadiSaleemi666, our test runners run on Linux, so Windows-specific behavior (like `.exe` extensions) won’t match what the tester expects.

I’d recommend using [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) for local development and testing. That will give you a Linux environment that’s much closer to what runs on CodeCrafters and should make debugging these path-related issues much easier.

---

<div class="post-metadata">

### Author: ![HadiSaleemi666](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/hadisaleemi666/32/26929_2.png) [@HadiSaleemi666](https://forum.codecrafters.io/u/HadiSaleemi666)
#### Post date: [June 24, 2026, 4:37am UTC](https://forum.codecrafters.io/t/question-regarding-mg5/16176/6 "2026-06-24T04:37:36Z")

</div>

Thats fair, though I suppose my question was geared more towards whether you could make the solution OS-agnostic. but I suppose this answer also answers that anyhow.

Thanks for the quick reply!

---

<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 29, 2026, 4:38am UTC](https://forum.codecrafters.io/t/question-regarding-mg5/16176/7 "2026-06-29T04:38:04Z")

</div>

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