Loading main.c +14 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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); } Loading Loading
main.c +14 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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); } Loading