# Shell cat Expected prompt ("$ ") but received ""

**URL:** <https://forum.codecrafters.io/t/shell-cat-expected-prompt-but-received/3619>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [December 22, 2024, 9:47pm UTC](https://forum.codecrafters.io/t/shell-cat-expected-prompt-but-received/3619 "2024-12-22T21:47:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DylanE415](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/dylane415/32/3654_2.png) [@DylanE415](https://forum.codecrafters.io/u/DylanE415)\
**Post date:** [December 22, 2024, 9:47pm UTC](https://forum.codecrafters.io/t/shell-cat-expected-prompt-but-received/3619/1 "2024-12-22T21:47:49Z")

</div>

I’m stuck on Stage #NI6.

I keep getting this error remote: [tester::#NI6] Expected prompt ("$ ") but received “” and Im not sure why. It occurs when the tester runs the cat command.

remote: [tester::#NI6] Running tests for Stage #NI6 (Quoting - Single quotes)  
remote: [tester::#NI6] Running ./your\_program.sh  
remote: [your-program] $ echo ‘hello script’  
remote: [your-program] hello script  
remote: [tester::#NI6] ✓ Received expected response  
remote: [your-program] $ echo script world  
remote: [your-program] script world  
remote: [tester::#NI6] ✓ Received expected response  
remote: [your-program] $ echo ‘example test’  
remote: [your-program] example test  
remote: [tester::#NI6] ✓ Received expected response  
remote: [tester::#NI6] Writing file “/tmp/qux/f 29” with content “grape pineapple.”  
remote: [tester::#NI6] Writing file “/tmp/qux/f 2” with content “blueberry banana.”  
remote: [tester::#NI6] Writing file “/tmp/qux/f 99” with content “grape pineapple.”  
remote: [your-program] $ cat ‘/tmp/qux/f 29’ ‘/tmp/qux/f 2’ ‘/tmp/qux/f 99’  
remote: [your-program] grape pineapple.blueberry banana.grape pineapple.  
remote: [tester::#NI6] Expected prompt ("$ ") but received “”  
remote: [your-program] $  
remote: [tester::#NI6] Assertion failed.  
remote: [tester::#NI6] Test failed

here is my code:

```python
import sys
import os
import subprocess
import pathlib
import shlex

def parse_args(args):
    args = shlex.split(args)
    return args
def find_executable_path(cmd):
    paths = os.getenv("PATH", "").split(os.pathsep)
    print(paths)
    for path in paths:
        executablePath = os.path.join(path, cmd)
        if os.path.isfile(executablePath):
            return executablePath
    return None
def cd(args):
    if args ==[]:
        print("cd: missing argument")
        return None
    if len(args) > 1:
        print("cd: too many arguments")
        return None
    path = args[0]
    if path.startswith('~'):
        path = os.path.expanduser(path)

    try:
        os.chdir(path)
    except Exception:
        print(f"cd: {path}: No such file or directory")
def ls(args):
    args=args
    if len(args)>1:
        print("ls: too many arguments")
    else:
        for x in(os.listdir(os.getcwd())):
            print(x, "-bytes:",os.path.getsize(x))

def exit(args):
    args=args
    if len(args)>1:
        print("exit: too many arguments")
    else:
        sys.exit(0)
def pwd(args):
    if len(args)>0:
        print("pwd: too many arguments")
    else:
        print(os.getcwd())

def echo(args):
    print(" ".join(args))
def cat(args):
    if not args:
        print("cat: missing argument")
    else:
        output=""
        for arg in args:
            try:
                with open(arg) as f:
                    output+=f.read()        
            except FileNotFoundError:
                print(f"cat: {arg}: No such file or directory")
                return
        print(output)
                
def type_cmd(args): 
    if len(args)>1:
        print("type: too many arguments")
    elif args in ("echo", "exit", "type", "pwd", "cd"):
        print(f"{args} is a shell builtin")
    else:
        executablePath = find_executable_path(args[0])
        if executablePath:
            print(f"{args[0]}:is {executablePath}")
        else:
            print(f"{args[0]}: not found")
builtin_commands={
    "cd":cd,
    "ls":ls,
    "exit":exit, 
    "pwd":pwd,
    "echo":echo,
    "type":type_cmd,
    "cat":cat
}

def main():

    while True:
        sys.stdout.write(f"$ ")
        full_command = input()
        if(full_command==""):
            continue
        args=parse_args(full_command)
        if args[0] in builtin_commands:
            builtin_commands[args[0]](args[1:])
        else:
            print(f"{args[0]}: 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:** [December 22, 2024, 10:16pm UTC](https://forum.codecrafters.io/t/shell-cat-expected-prompt-but-received/3619/2 "2024-12-22T22:16:50Z")

</div>

Hi @DylanE415, I tried running your code against the previous stages, but it’s actually no longer passing the **#EZ5 (The type builtin: builtins)** stage.

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

Suggestions:

1. Use [our CLI](https://docs.codecrafters.io/cli/installation) to test against previous stages by running:

```auto
codecrafters test --previous

```

1. Focus on fixing the early stages first, as later stages depend on them.

---

<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:** [December 22, 2024, 10:28pm UTC](https://forum.codecrafters.io/t/shell-cat-expected-prompt-but-received/3619/3 "2024-12-22T22:28:01Z")

</div>

For #NI6, our tester is not expecting a newline at the end of the cat output:

```auto
def cat(args):
    ...
    else:
        ...
        print(output, end="")

```

---

<div class="post-metadata">

**Author:** ![DylanE415](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/dylane415/32/3654_2.png) [@DylanE415](https://forum.codecrafters.io/u/DylanE415)\
**Post date:** [December 22, 2024, 11:03pm UTC](https://forum.codecrafters.io/t/shell-cat-expected-prompt-but-received/3619/4 "2024-12-22T23:03:44Z")

</div>

I fixed previous error, needed to have end=“” so it doesn’t add a newline print(output,end=“”)

---

<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:** [December 27, 2024, 11:04pm UTC](https://forum.codecrafters.io/t/shell-cat-expected-prompt-but-received/3619/5 "2024-12-27T23:04:30Z")

</div>

Closed on December 27, 2024, 11:04pm UTC

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