Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I create a pipe in which i switch stdout by its writing side so i can get the result of execvp.
- if(pipe(exec2reduce) == -1) {
- perror("pipe");
- return -1;
- }
- if(dup2(exec2reduce[1],1) == -1) {
- perror("dup2");
- return -1;
- }
- //I create a new process using fork to run execvp but the parent waits idefinitely.
- pid = fork();
- if(pid == -1) {
- perror("fork");
- return -1;
- }
- if(pid == 0) {
- if(execvp(command,args) == -1) {
- perror("execvp");
- _exit(EXIT_FAILURE);
- }
- _exit(EXIT_SUCCESS);
- }
- wait(&retvar);
- if(!WIFEXITED(retvar)) {
- return -1;
- }
- else {
- if(WEXITSTATUS(retvar) == EXIT_FAILURE) {
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment