Redirection

When running programs, it is useful to provide input from a file or to direct output to a file. The syntax [process] > [file] tells your shell to redirect the process’s standard output to a file. Similarly, the syntax [process] < [file] tells your shell to feed the contents of a file to the process’s standard input.

Modify your shell so that it supports redirecting stdout and stdin to/from files.

You do not need to support redirection for shell built-in commands. You do not need to support stderr redirection or appending to files (e.g. [process] >> [file]). You can assume that there will always be spaces around special characters < and >. Be aware that < [file] or > [file] are not passed as arguments to the program (i.e. you will not find these characters in the argv argument of the main function in shell.c). You will, however, be able to access them via struct tokens* tokens.

You should add proper error handling for cases where the '<' and '>' are used incorrectly, i.e. either of those is not followed by a valid file name. For instance wc < > should report a shell: syntax error near unexpected token '>' error to stderr. Please refer to the test suite to see what error messages are expected for various cases.

Next task: read about Pipes.