I need to make an argument vector to pass to execv()... I'm creating it like shown below, I've tested it so I know all my strings are getting null termininated etc... but any programs I execute with execv() complain they aren't getting their arguments.
Can anyone find the subtle thing wrong here?
Code:char* argv[MAX_ARGS] = { 0 }; // need this to pass to execv() string argument; stringstream ss; ss << input; ss >> command; int i = 0; if ( command.size() != input.size() ) // were there arguments? { arguments = input.substr(command.size()+1); // make an argument string. while ( (ss >> argument) && (i < (MAX_ARGS-1)) ) // create argument vector. { argv[i] = new char[argument.size()+1]; // allocate memory memset(argv[i], '\0', argument.size()+1); // null it out argument.copy(argv[i], argument.size()); // copy argument to argv i++; } argv[i] = '\0'; // make last element null } /* child */ execv((path+command).c_str(), argv);



LinkBack URL
About LinkBacks



