This is an exercise in launching a child process and setting up file redirection.
We will be implementing the equivalent of
“command 2> filename
”.
The finished program err-redir
will take 2 or more arguments:
filename, program to run, command line arguments for that program. Example:
./err-redir xyz ls dnemeans to run
ls dne
, and its stderr should go to filename xyz.
(Since dne does not exist, there should be an error message in xyz.)
The provided starter file err-redir.c already has a skeleton. But there are many things to complete or fix (marked by “TODO”); please see the file for specifications.
Some sample programs are provided: sample (shell script) and check-open.c. Please take a look at what they do and how they help you test.
But here are some sample sessions:
$ ./err-redir xyz ls dne exit: 2 $ cat xyz ls: cannot access 'dne': No such file or directory $ ./err-redir xyz ./sample 7 exit: 7 $ cat xyz hi $ ./err-redir xyz ./sample signal signal: 15 $ ./err-redir xyz ./sample po total 0 lrwx------ 1 trebla trebla 64 Jul 9 14:27 0 -> /dev/pts/0 lrwx------ 1 trebla trebla 64 Jul 9 14:27 1 -> /dev/pts/0 lrwx------ 1 trebla trebla 64 Jul 9 14:27 2 -> /dev/pts/0 exit: 0 $ ./err-redir xyz ./check-open AOK exit: 0 $ ./err-redir xyz ./err-redir.c cannot exec: Permission denied exit: 126 $ ./err-redir xyz asdfqwerty cannot exec: No such file or directory exit: 127