Question

I've been trying to run command using exevp as follows:

char *args[11];
args[0] = (char*)lgulppath.c_str();
args[1] = (char*)"-i";
args[2] = (char*)sniffer_interface.c_str();
args[3] = (char*)"-r";
args[4] = (char*)pcapfileLimit.c_str();
args[5] = (char*)"-C";
args[6] = (char*)"1";
args[7] = (char*)"-f";
args[8] = (char*)serverip_filter.c_str();
args[9] = (char*)"-o";
args[10] = (char*)lpipepath.c_str();
execv("/usr/sbin/program",args);

this works. HOWEVER, when I want to have the first parameter "/usr/sbin/program" as a parameter say:

string str = "/usr/sbin/program";
//char* args is assigned as above
execv(str.c_str(),args);

this fails and returns -1. I CAN'T GET WHY THOUGH.

Thanks everybody

Was it helpful?

Solution

Null terminate the arguments you pass to execv. Something like

char *args[12];
// other args..
args[11] = (char*) 0;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top