diff --git a/src/command.c b/src/command.c index 7a55fed..dd7396b 100644 --- a/src/command.c +++ b/src/command.c @@ -6,12 +6,14 @@ #include unsigned char invoke(struct Args args) { + int status; + pid_t child = fork(); if (child == 0) { execvp(args.argv[0], args.argv); exit(errno); } - waitpid(child, NULL, 0); + wait(&status); - return 0; + return WEXITSTATUS(status); } diff --git a/src/main.c b/src/main.c index 5e073d1..e776132 100644 --- a/src/main.c +++ b/src/main.c @@ -7,19 +7,20 @@ int main() { char *input_line; + unsigned char exit_code = 0; while (1) { printf("$ "); input_line = read_a_line(stdin); if (input_line == NULL) { - return 0; + return exit_code; } struct Args args = parse(input_line); free(input_line); if (args.argc > 0) { - invoke(args); + exit_code = invoke(args); } {