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:
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
Hi @microwavestine, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.
I’ve published it here https://github.com/microwavestine/codecrafters-shell-python
I’ve also tried the following code (will delete later):
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()
Hi @microwavestine, the bug is here:
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].
For example, try something like this instead: