Question
I/O redirection in C shell Please implement input / output redirection in the code posted below. Here are the specs: Your shell will need to
I/O redirection in C shell
Please implement input / output redirection in the code posted below. Here are the specs:
Your shell will need to support file redirection. Use the same syntax as defined in the Bash shell: a single '>' implies that one needs to redirect the standard output of the program being started to the referenced file while a single '<' implies the same with standard input. The double '>>' implies that standard output will append to an existing file rather than create a new file (similar behavior is required for the '<<' operator and standard input). You do not need to implement support for the Bash pipeline operator '|'.
Before calling exec to begin execution, the child process may have to close stdin (file desriptor 0) and/or stdout (file descriptor 0), open the corresponding file and use the dup2 system call to make it the appropriate file descriptor. Don't forget to use the close system call to close the old file descriptor.
#include
using namespace std;
int change_dir(char* args[]) { if (args[1] == NULL) { chdir(getenv("HOME")); return 1; } else { if (chdir(args[1]) == -1) { cout << "No such directory" << args[1]; return -1; } } return 0; }
int helper_func(char* args[]) { cout << "Builtin commands so far are; cd, and help. "; return 0; }
int main() { while(true) { cout << "$ "; char cmd[128]; cin.getline(cmd,128); vector
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