I'm trying to make a shell that whenever it can't execute a command it says "Error executing binary: -nameOfBinary-". But the thing is that it always gives me the message "No such file or directory". Heres part of my code:
void handle_SIGINT() {
write(STDOUT_FILENO,line,strlen(line));
printf("\n");
struct sigaction handler;
handler.sa_handler = handle_SIGINT;
sigaction(SIGINT, &handler, NULL);
}
void runcommand(char* argv[]) {
int p =fork();
if(p==0) {
struct sigaction handler;
handler.sa_handler = SIG_IGN;
sigaction(SIGINT, &handler, NULL);
execvp(argv[0],argv);
perror("Error executing binary");
exit(1);
} else {
wait(NULL);
}
}
With the code as it is it always gives me the message "Error executing binary: No such file or directory" which is close to what I want! How can I fix it? Thanks in advance!