Question: Shell.c: #include #include #include #include #include #include #include #include #include #include #define BUFFER_LENGTH 1024 using namespace std; int main(){ //set the variables char line[BUFFER_LENGTH]; char*

 Shell.c: #include #include #include #include #include #include #include #include #include #include

#define BUFFER_LENGTH 1024 using namespace std; int main(){ //set the variables char

Shell.c:

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define BUFFER_LENGTH 1024

using namespace std;

int main(){

//set the variables

char line[BUFFER_LENGTH];

char* argv[100];

char* path= "/bin/";

char execmd[20];

int arguments;

while(1){

//begin the shell command line

printf("My shell>> ");

if(!fgets(line, BUFFER_LENGTH, stdin)){

size_t length = strlen(line);

if (line[length - 1] == ' ')

line[length - 1] = '\0';

}

if(strcmp(line, "exit")==0){

break;

}

char *token;

token = strtok(line," ");

int i=0;

while(token!=NULL){

argv[i]=token;

token = strtok(NULL," ");

i++;

}

argv[i]=NULL;

arguments=i;

for(i=0; i

printf("%s ", argv[i]);

}

strcpy(execmd, path);

strcat(execmd, argv[0]);

for(i=0; i

if(execmd[i]==' '){

execmd[i]='\0';

}

}

int pid = fork();

if(pid==0){

execvp(execmd,argv);

fprintf(stderr, "Child process could not do execvp ");

//exit the child

}else{

wait(NULL);

printf("Child exited ");

}

}

}

Update the shell program (shell.c) so that it handles I/O redirection and pipes similar to the way the shell (bash of your Linux account handles as following. (i) The I/O redirection commands you must handle are filename takes standard input from the given file >filename sends standard output to the given file To make parsing easier, you can assume that there is no space between the file name and the characters and You can also assume that I/O redirection appears after the command and all options for the command. For example, the following command lines are legal ls -1-F -a list ps aux plist You don't have to womy about command lines like ls -1 list -F -a ps plist aux cat list1 list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!