After calling exec() or one, if its relatives, your original program no longer exists. This means that nothing in this program can affect anything after calling exec() , since it never starts. Maybe you are not building your array of arguments correctly? Here is a quick working example of execvp() :
#include <unistd.h> int main(void) { char *execArgs[] = { "echo", "Hello, World!", NULL }; execvp("echo", execArgs); return 0; }
On the execvp() page:
The functions execv() , execvp() and execvpe() provide an array of pointers to null-terminated strings that represent the argument list available for the new program. The first argument, by convention, should point to the file name associated with the executable. An array of pointers must be interrupted by a NULL pointer.
A common mistake is to skip the part "The first argument, by convention, should point to the file name associated with the executable file." That the part that provides echo receives an "echo" like argv[0] , which apparently depends on.
source share