Some test cases failing for Redirect stdout #jv1

I need help understanding the challenge.

Here is my code: GitHub - ehizman/unix-shell-java-impl: A simple implementation of a Unix shell in Java.

Tests fail with this error:

[tester::#JV1] Running tests for Stage #JV1 (Redirection - Redirect stdout)
[tester::#JV1] [setup] export PATH=/tmp/grape/pear/strawberry:$PATH
[tester::#JV1] Running ./your_program.sh
[tester::#JV1] [setup] echo -n "apple" > "/tmp/qux/apple"
[tester::#JV1] [setup] echo -n "orange" > "/tmp/qux/orange"
[tester::#JV1] [setup] echo -n "raspberry" > "/tmp/qux/raspberry"
[your-program] $ ls -1 /tmp/qux > /tmp/bar/bar.md
[your-program] $ cat /tmp/bar/bar.md
[your-program] orange
[tester::#JV1] Output does not match expected value.
[tester::#JV1] Expected: "apple"
[tester::#JV1] Received: "orange"
[your-program] apple
[your-program] raspberry

I understand why the order of the expected output keeps changing

Hey @ehizman, you probably don’t need to implement your own ls. It’s available as an executable on most systems:

That said, if you’d like to keep your custom implementation, make sure it sorts files alphabetically by name (in ascending order) to match the default behavior of ls:

Let me know if you’d like further clarification!

Oh wow.
I commented out my custom implementation of ls and cat and then checked the scanner input for a redirect, if the scanner input contains a redirect, I set the system output to the redirect target. Unfortunately, I still get this error:

[tester::#JV1] Running tests for Stage #JV1 (Redirection - Redirect stdout)
[tester::#JV1] [setup] export PATH=/tmp/mango/banana/mango:$PATH
[tester::#JV1] Running ./your_program.sh
[tester::#JV1] [setup] echo -n "mango" > "/tmp/qux/mango"
[tester::#JV1] [setup] echo -n "orange" > "/tmp/qux/orange"
[tester::#JV1] [setup] echo -n "pineapple" > "/tmp/qux/pineapple"
[your-program] $ ls -1 /tmp/qux > /tmp/quz/bar.md
[tester::#JV1] Expected prompt ("$ ") but received ""
[tester::#JV1] Assertion failed.
[tester::#JV1] Test failed

I need help figuring this out. Do you mind @andy1li .
Thanks

Seems like when the command is executed, the shell remains “stuck” in the process of execution of the command and writing to the file, and does not print the prompt $ again. I haven’t taken a look at the code yet (as I’m not really well versed in Java), but my guess would be this is because not closing the resources appropriately after the execution, like perhaps the file that you are opening to redirect the output to, or the runtime.exec that you must be using to run the executable mentioned in the command.

1 Like

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.