int launch(char *path, char **av, char ***env, t_fd *fd) { if (dup2(fd->in, 0) == -1) return (-1); if (dup2(fd->out, 1) == -1) return (-1); if (dup2(fd->err, 2) == -1) return (-1); if ((execve(path, av, *env)) == -1) return (launch_error(path)); return (0); }
/*---------------------------------------------------------------------*/ static pid_t exec_hop( char *msg ) { int pid; /* show the waiting widget */ gui_start_waiting( msg ); if( (pipe( hop_pipe_stdout ) < 0) || (pipe( hop_pipe_stderr ) < 0) ) { launch_error( "Cannot create pipe", strerror( errno ) ); } switch( pid = fork() ) { case -1: launch_error( "Cannot fork", strerror( errno ) ); return -1; case 0: /* redirect to the pipe */ if( dup2( hop_pipe_stdout[ 1 ], 1 ) < -1 ) { launch_error( "Cannot duplicate stdout", strerror( errno ) ); } if( dup2( hop_pipe_stderr[ 1 ], 2 ) < -1 ) { launch_error( "Cannot duplicate stderr", strerror( errno ) ); } /* exec the hop process */ if( exec( get_hop_command( hop_command ) ) == -1 ) { launch_error( "Cannot start hop", strerror( errno ) ); } return -1; default: /* the parent process */ return pid; } }