0

When trying to use the execve command, I receive an error about my last 2 arguments.

     #include <unistd.h>        
     const char * c = enviorment.c_str();
     execve(full.c_str() , cl.getArgVector(), c);

I've tried using the several different options in copying strings such as:

char *temp2 = new char[(path).size()+1];
strcpy ( temp2, cl.getCommand());
    execve(full.c_str() , cl.getArgVector(), temp);

but I'm unable to get it to work and recieve an error message:

error: cannot convert char* to char* const* for argument 3 to int execve(const char*, char* const*, char* const*)

user1797035
  • 128
  • 7
  • What does `enviorment` look like? Is it a single key/value pair in the form of `"KEY=VALUE"` or is it multiple delimited key-vars? – Jorge Israel Peña Mar 27 '13 at 02:53
  • @JorgeIsraelPeña I believe that's environment-specific (*ba-dun-tss*) – Richard J. Ross III Mar 27 '13 at 02:56
  • @RichardJ.RossIII Ah okay, indeed, from the man page it seems that's a convention, but not necessarily enforced/a requirement. I was mistakenly under the impression that it was required to be an array of strings in the form of `"KEY=VALUE"`. Still though, I asked to know if we should split his `environment` string, depending on how his environment's `execve` expects the `envp` parameter. – Jorge Israel Peña Mar 27 '13 at 02:59

1 Answers1

0

The environment variable array is an array of strings (char*), not one string. It needs a NULL value as the final element in the array.

Mimic the code you're using to implement c1.getArgVector() making sure the last char* in the array is NULL.

jeffmagill
  • 191
  • 1
  • 6