Commit bc475ad0 authored by Matthew Burket's avatar Matthew Burket

Got the forking working more or less

parent 67fa60fd
Pipeline #323 canceled with stage
......@@ -133,21 +133,26 @@ int main() {
fprintf(stderr, "Unable to create the pipe. Aborting.");
exit(EXIT_FAILURE);
}
// Got the idea for forking from:
// https://stackoverflow.com/a/13803962
if (fork() == 0) {
if (doMoreCheck != 0) {
close(STDOUT_FILENO);
dup(thePipe[1]);
close(thePipe[0]);
close(thePipe[1]);
}
int returnCode = execvp(tokens[0], tokens);
close(thePipe[1]);
if (returnCode == -1) {
fprintf(stdout, "bsh: Command not found\n");
}
printf("\n");
exit(1);
} else {
if (runInBackground == 0) {
if (runInBackground == 0 && doMoreCheck == 0) {
wait(NULL);
}
runInBackground = 0;
}
// Do if more fork, otherwise short cricut and move on with life
......@@ -155,12 +160,15 @@ int main() {
close(STDIN_FILENO);
dup(thePipe[0]);
close(thePipe[1]);
char* moreCmd[] = {"more"};
execvp(moreCmd[0], moreCmd);
close(thePipe[0]);
exit(EXIT_SUCCESS);
char* moreCmd[] = {"more", 0};
execvp(moreCmd[0], moreCmd);
exit(1);
} else if (doMoreCheck != 0) {
// wait(NULL);
close(thePipe[0]);
close(thePipe[1]);
wait(0);
wait(0);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment