Search code examples
c++execl

Call execl on a non-const char[]


I'm getting the comand from keyboard in a vector<string> and I want to use in execl(), but execl() takes a const char *. Is there another function similar to execl I can use that takes char* parameters, or how can I call execl with my char*?

void Process::exec(string & program, vector<string> & params){
int i;
char x=program[0];
if(x=='/'){
    char * argq[params.size()];
        for(i=0;i<params.size();i++){
            argq[i]=(string_to_c_convert(params[i]));
        }

    if(params.size()==2){
        execl(argq[0],argq[0],(char *)0);
    }
    if(params.size()==3){
        execl(argq[0],argq[1],argq[2],(char *)0);
    }
}

Solution

  • const char * doesn't mean that the argument must be const, it means it can be const.

    There is no problem here to solve.