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:
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:
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.