Loading main.c +17 −4 Original line number Diff line number Diff line Loading @@ -146,32 +146,43 @@ int main() { if (returnCode == -1) { fprintf(stdout, "bsh: Command not found\n"); } // Clean up and we are done; printf("\n"); exit(1); } else { // Wait where if no & and not a pipe if (runInBackground == 0 && doMoreCheck == 0) { wait(NULL); } // Reset the background thing runInBackground = 0; } // Do if more fork, otherwise short cricut and move on with life if (doMoreCheck != 0 && fork() == 0) { // Close Stdin close(STDIN_FILENO); // Make stdin the pipe dup(thePipe[0]); // Close the pipes close(thePipe[1]); close(thePipe[0]); char* moreCmd[] = {"more", 0}; // During recitation the TA stated only supporting more is okay // The NULL is important, Pro tip. char* moreCmd[] = {"more", NULL}; execvp(moreCmd[0], moreCmd); // We done, exit exit(1); } else if (doMoreCheck != 0) { // Close pipes close(thePipe[0]); close(thePipe[1]); wait(0); wait(0); // Wait on the children to finish playing wait(NULL); wait(NULL); } // Free the tokens free(tokens); } } Loading @@ -183,6 +194,8 @@ void storeHist(char **readBuff, int *historyPos, char historyBuff[50][5000], int for (int i = 0; i < numTokens - 1; i++) { strcat(historyBuff[*historyPos], readBuff[i]); int nextIter = i + 1; // No space the end // if (nextIter < numTokens - 1) { strcat(historyBuff[*historyPos], " "); } Loading Loading
main.c +17 −4 Original line number Diff line number Diff line Loading @@ -146,32 +146,43 @@ int main() { if (returnCode == -1) { fprintf(stdout, "bsh: Command not found\n"); } // Clean up and we are done; printf("\n"); exit(1); } else { // Wait where if no & and not a pipe if (runInBackground == 0 && doMoreCheck == 0) { wait(NULL); } // Reset the background thing runInBackground = 0; } // Do if more fork, otherwise short cricut and move on with life if (doMoreCheck != 0 && fork() == 0) { // Close Stdin close(STDIN_FILENO); // Make stdin the pipe dup(thePipe[0]); // Close the pipes close(thePipe[1]); close(thePipe[0]); char* moreCmd[] = {"more", 0}; // During recitation the TA stated only supporting more is okay // The NULL is important, Pro tip. char* moreCmd[] = {"more", NULL}; execvp(moreCmd[0], moreCmd); // We done, exit exit(1); } else if (doMoreCheck != 0) { // Close pipes close(thePipe[0]); close(thePipe[1]); wait(0); wait(0); // Wait on the children to finish playing wait(NULL); wait(NULL); } // Free the tokens free(tokens); } } Loading @@ -183,6 +194,8 @@ void storeHist(char **readBuff, int *historyPos, char historyBuff[50][5000], int for (int i = 0; i < numTokens - 1; i++) { strcat(historyBuff[*historyPos], readBuff[i]); int nextIter = i + 1; // No space the end // if (nextIter < numTokens - 1) { strcat(historyBuff[*historyPos], " "); } Loading