Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<string> args;
- /* code that correctly parses args from user input */
- pid_t kidpid = fork();
- if (kidpid < 0)
- {
- perror("Internal error: cannot fork.");
- return -1;
- }
- else if (kidpid == 0)
- {
- // I am the child.
- vector<char*>argcs;
- for(int i=1;i<args.size();i++)
- {
- char * temp = new char[args.at(i).length()];
- for(int k=0;k<args.at(i).length();k++)
- {
- temp[k] = args.at(i).at(k);
- }
- argcs.push_back(temp);
- }
- char** argv = new char*[argcs.size() + 1];
- for (int i = 0; i < argcs.size(); i++)
- {
- argv[i] = argcs[i];
- }
- argv[args.size()] = NULL;
- execvp(program, args);
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement