Add a bit of I/O redirection to your shell.
Support the following command form:
mysh$ cmd arg1 arg2 argN > file.out
The '>' character should be followed by a file name. It means "redirect the stdout of this command to this file".
mysh$ echo hello > a.txt
mysh$ echo world > b.txt
mysh$ cat a.txt b.txt > c.txt
mysh$ cat c.txt
- Stdout is always file descriptor number 1. You can close stdout by calling either close(1) or fclose(stdout).
- Whenever you open a file, it is assigned the lowest available file descriptor.
- A forked child process has its own file descriptor table, so it is possible to have a child with a different stdout than its parent