Commits

Steven! Ragnarök  committed 96c172c

Check for exec failure and exit the child process with status 127.

  • Participants
  • Parent commits cde13b8

Comments (0)

Files changed (1)

File src/interpreter.c

 }
 
 int interpret_command(ast_node* command) {
-	int cmdstats, argc = 0;
+	int cmdstats, argc = 0, execerr;
 	pid_t cmdpid;
 	char *argv[MAX_TOKEN_LENGTH];
 	ast_nodelist *arg = command->children;
 	argv[argc] = NULL;
 	cmdpid = fork();
 	if (!cmdpid)  {
-		execvp(command->token, argv);
+		execerr = execvp(command->token, argv);
+		if (execerr == -1) {
+			fprintf(stderr, "sh142: %s: command not found.\n", argv[0]);
+			exit(127);
+		}
 	} else {
 		waitpid(cmdpid, &cmdstats, 0);
 	}