Errors travel on their own channel - file descriptor 2 - so you can capture them separately from normal output. Today you add `2>` to send a command's error stream to a file.
Implement `2> file` so the command's standard error is written to that file, leaving standard output alone.
Programs actually have two output channels: standard output (fd 1) for
normal results, and standard error (fd 2) for diagnostics and error
messages. Keeping them separate is what lets you pipe a command’s real output
somewhere while still seeing its errors on screen - or, with 2>, capture just
the errors into a file. 2> is > aimed at descriptor 2 instead of 1.
Your redirection record already carries a target and a mode; the new piece is
which descriptor a redirection applies to. Generalize it to name the fd - 1
for >, 2 for 2> - and the apply step becomes “open the target, dup2 it
onto that fd.” With the descriptor number explicit, tomorrow’s trick of pointing
one descriptor at another falls out naturally.
// 2> targets fd 2 specifically, not fd 1int fd = open(target, O_WRONLY | O_CREAT | O_TRUNC, 0644);dup2(fd, 2); // stderr -> file; stdout untouchedclose(fd);