Right, that’s what I understood as well. I’m running a function separately on every loop iteration, not preloading anything.
When I print the contents of the PATH variable I get this:
/tmp/banana/banana/grape:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
For readability:
/tmp/banana/banana/grape
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
The temporary directory is created and placed at the beginning of the PATH. It should found the my_exe
executable there.
I’ve just changed things up so that instead of printing “my_exe: not found” it prints the PATH variable, so we can see clearly whether it’s there or not, and it’s in fact loaded properly:
[tester::#MG5] Expected: "my_exe is /tmp/grape/strawberry/strawberry/my_exe"
[tester::#MG5] Received: "/tmp/grape/strawberry/strawberry:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
If I return that path directly, it works fine. Which makes me think that the my_exe
file is never actually there to be found.
char *path_var = getenv("PATH");
char *path_env = strndup(path_var, strlen(path_var));
path_env = strtok(path_env, ":");
if (strncmp(cmd, "my_exe", strlen(cmd)) == 0)
return path_env;
Also note, regarding the other error, that it expects to find certain commands in /bin
but /usr/bin
comes first in the PATH:
[tester::#MG5] Expected: "cp is /bin/cp"
[tester::#MG5] Received: "cp is /usr/bin/cp"