I’m stuck on Stage Single quotes #NI6.
i have tried to use execvp to execute the files passed with the cat command and it always keeps returning permission denied, i have a hunch it may be because of how the file names are passed (which are the same as the file paths given as arguments alongside the cat command except with the single quotes) but I still dont have any idea on how to fix it. i have printed the file paths i am passing into the function in the logs.
Here are my logs:
remote: [tester::#NI6] Writing file "/tmp/baz/f 50" with content "blueberry orange."
remote: [tester::#NI6] Writing file "/tmp/baz/f 80" with content "orange pineapple."
remote: [tester::#NI6] Writing file "/tmp/baz/f 29" with content "grape pineapple."
remote: [your-program] $ cat '/tmp/baz/f 50' '/tmp/baz/f 80' '/tmp/baz/f 29'
remote: [tester::#NI6] Output does not match expected value.
remote: [tester::#NI6] Expected: "blueberry orange.orange pineapple.grape pineapple."
remote: [tester::#NI6] Received: "/tmp/baz/f 50"
remote: [your-program] /tmp/baz/f 50
remote: [your-program] execvp: Permission denied
remote: [your-program] /tmp/baz/f 80
remote: [your-program] execvp: Permission denied
remote: [your-program] /tmp/baz/f 29
remote: [your-program] execvp: Permission denied
remote: [your-program] $
remote: [tester::#NI6] Assertion failed.
remote: [tester::#NI6] Test failed
And here’s a snippet of my code:
void excuteProgramWCat(string fPath) {
pid_t pid = fork();
if(pid == 0) { //Child process (excutes the excutable)
const char* args[] = {fPath.c_str(), nullptr};
cout << fPath.c_str() << endl;
execvp(fPath.c_str(), const_cast<char* const*>(args));
perror("execvp"); // If exec fails
exit(1);
} else if(pid > 0 ) { //Parent process (excutes the actual program)
int status;
waitpid(pid, &status, 0); // waits until the child process has excuted the file and exits
}
}