I wrote a test program to try and understand how to use execvp(), but I keep running into a problem. The relevant part of my code is:
...
printf("execute: 'ls -a'\n");
char *args[2];
args[0] = "/bin/ls";
args[1] = "ls";
args[2] = "-a";
...
} else if(pid == 0){ //child process
if(execvp(*args, args) < 0) { //execute command
fprintf(stderr, "Error: execution failed\n");
exit(1);
}
}
...
Whenever I run, I get an error "/bin/ls: cannot access ls: No such file or directory". which ls
tells me /bin/ls so I don't understand what I'm doing wrong. Is it because the executable file isn't in my home directory but rather a projects file?