sophiakoulen / minishell

A simplified bash-like shell, with pipes, redirections and variable expansion.
4 stars 1 forks source link

In non-interactive mode, cat doesnot work when reading from stdin #115

Closed sophiakoulen closed 1 year ago

sophiakoulen commented 1 year ago
➜  minishell git:(main) ✗ echo '
quote> cat
quote> hello
quote> world
quote> ' | bash
hello
world

➜  minishell git:(main) ✗ echo '
quote> cat
quote> hello
quote> world
quote> ' | ./minishell
minishell: hello: command not found
minishell: world: command not found
exit
➜  minishell git:(main) ✗
sophiakoulen commented 1 year ago

This was because of 42's beloved get_next_line() function. Reading to more characters than needed and putting it in a static buffer is problematic when we need to let another function that does not use get_next_line tries to read from the file descriptor. I don't suppose we're allowed to move the cursor of a file descriptor back with our authorized functions so our current best solution is to compile with -DBUFFER_SIZE=1. It's bad performance but we're not even supposed to handle non-interactive mode so that will do.

sophiakoulen commented 1 year ago

Fixed with 871dc59ee2c34f59e5afd87df6e062f289459819