Thepurposeofthisassignmentistomakesurethatthestudentscanworkeffectivelywiththe fork , pipe , and dup , system calls. It should also grant some insight into how the shell enables input and output redirection behind the scenes.
For this assignment, you will be writing a single program that enters a loop in which each iteration prompts the user for two, single-line inputs. If the text entered for either of these is quit , then the program should immediately exit. If quit is not found, then each of these lines of input will be treated as a command line to be executed. These two commands should be executed so they behave as if the user had typed command1 | command2 at the shell prompt. This means that the standard output of the first command will be redirected into the standard output of the second command.
It should be noted that using cin >> will not grab a whole line; you will need another function to get the whole line.
You will need to be able to split the text entered by the user into the individual command line arguments that comprise it. I do not care how you accomplish this, as long as it's either part of the standard library or code that you wrote entirely on your own. Possibilities include the C function strtok or the C++ istringstream object. You do not need to worry about escaping special characters while splitting the string for the purposes of this assignment; the split can be performed based on spaces alone.
After these commands have both finished executing, your program should prompt for another pair of input commands to run, repeating the procedure over and over again until the program receives quit as one of its inputs.
% ls
a b c def example typescript
% ls | wc
6 6 29
% ls -a
. .. a b c def example typescript
% ls -a | wc -w
8
% ./assign5
command1? ls
command2? wc
6 6 29
command1? ls -a
command2? wc -w
8
command1? quit
%