Question
In C, write a program called 'chaining' that does the following: 1. Prompts user for an input file. Assume the filename is less than 1000
In C, write a program called 'chaining' that does the following:
1. Prompts user for an input file. Assume the filename is less than 1000 chars. It will ask for a file by printing 'Enter an input file now: '.
2. Prompts user for the 1st command to run as a single input line. Assume the input line is less than 4000 chars. It will ask for the command by printing 'Enter the first command now: '.
3. Prompts user for the 2nd command to run as a single input line. Again, assume the input line is less than 4000 chars. It will ask for the command by printing 'Enter the second command now: '.
4. Prompts user for the 3rd command to run as a single input line. Assume the input line is less than 4000 chars. It will ask for the command by printing 'Enter the third command now: '.
5. Prompts user for an output file. Assume the filename is less than 1000 chars. It will ask for the file by printing 'Enter an output file now: '.
6. The program should then execute the 3 commands. The 1st command gets its input from the input file. The 1st commands input will be redirected to the input of the 2nd command. The 2nd commands input will be redirected to the input of the 3rd command. The 3rd commands output will go into the output file.
Note:
- The output file should not be appended to but replaced instead.
- Don't use the system() function call - use an exec call to run the commands.
UPDATE:
You can check your program by comparing what happens if you run the following at the Linux/MacOS shell:
first_command < input_file | second_command | third_command > output_file
Example: cat < /etc/passwd | sort -t : -n | head -15 > sorted_beginning_of_etc_passwd.txt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started