I'm stuck in the run files section

I’m stuck on Stage #IP1.

I’ve tried checking whether the input string is a file using both os.path.isfile and shutl.which and it doesn’t seem to recognize the custom_exe_1234 as an executable file.

Here are my logs:

include relevant logs here (please make sure to keep the backticks around this!)

And here’s a snippet of my code:

import sys
import shutil
import os

builtins = ["exit", "echo", "type"]

def shell_type(args):
    if args[0] in builtins:
        sys.stdout.write(f"{args[0]} is a shell builtin\n")

    elif path := shutil.which(args[0]):
        sys.stdout.write(f"{args[0]} is {path}\n")

    else:
        sys.stdout.write(f"{args[0]}: not found\n")


def main():
    # Uncomment this block to pass the first stage
    sys.stdout.write("$ ")

    # Wait for user input

    command = input()

    if command == "exit 0":
        command_parts = command.split()
        exit(int(command_parts[1]))

    elif "type" in command:
        command_parts = command.split()
        shell_type(command_parts[1:])

    elif "echo" in command:
        command_parts = command.split()
        sys.stdout.write(f"{' '.join(command_parts[1:])}\n")

    else:
        if shutil.which(command.split(" ")[0]):
            os.system(command)
        else:
            sys.stdout.write(f"{command}: not found\n")

    main()


if __name__ == "__main__":
    main()

Hi @webmaster99-stack, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Hey @webmaster99-stack, sorry for the delayed response!

Here’s what you can do:

  1. Read the PATH environment variable.
  2. Loop through each directory listed in PATH, and check if the executable exists in any of them.

Let me know if you’d like further clarification!

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

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