Question: can some on ehelp me modify my code. its a C language. my shell does not have a pipe. beased on the following instructions please
can some on ehelp me modify my code. its a C language. my shell does not have a pipe. beased on the following instructions please help me modify the code.You should store pointers to the substrings in an array similar to the argv array passed to main and pass this array of arguments to execvp Note that the number of commandline arguments is variable; this is indicated in the array by including a NULL pointer in the array after the last substring. This means that if the user specifies N substrings, your array must hold N pointers where the last pointer is NULL. If the user enters the exit command, your shell should terminate returning to the regular shell
Note: your shell does not need to support cd change directory
Piping You shell must also support piping. An example of using pipes in the Linux shell would be cat myfile.txt wc l which would copy the file myfile.txt to standard output which is redirected as the standard input to wc wordcount which will then display how many lines were in the file myfile.txt The pipe character seperates different commands and the output stdout of the program on the left becomes the input stdin for the program on the right. There is no limit to the number of commands that can be piped together. Just limited by the command line length specified above
Hint: get your shell working without pipes first, then go back and add pipes. While this may require a little more work to change your code to support pipes, it ensures you do the rest of the shell correctly so you are not trying to debug multiple things at once. Some functions you will need include pipe and dup
Your program must also accept a command line argument which is the prefix prompt. If no value is specified use as the prompt. #include
#include
#include
#include
#include
#include
#define MAXINPUTSIZE
#define MAXARGS
void executecommandchar args
pidt pid;
int status;
pid fork;
if pid
Child process
if execvpargs args
perrorError executing command";
exitEXITFAILURE;
else if pid
perrorError forking process";
else
Parent process
waitpidpid &status, ;
printfChild PID: d Return result: d
pid, WEXITSTATUSstatus;
int mainint argc, char argv
char inputMAXINPUTSIZE;
char argsMAXARGS;
char token;
const char delim;
if argc
printfs argv;
else
printf;
while fgetsinput sizeofinput stdin NULL
if input
fprintfstderr "Error: Empty command
;
if argc
printfs argv;
else
printf;
continue;
inputstrcspninput
; Remove newline character
int i ;
token strtokinput delim;
while token NULL && i MAXARGS
argsi token;
token strtokNULL delim;
i;
argsi NULL; Set the last element of the array to NULL
if strcmpargs "exit"
break;
executecommandargs;
if argc
printfs argv;
else
printf;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
