static int pipline(char **args, int argsNb,int bg, int pip0, int pip1, char *pipeArgs){ printf("in pipline function\n"); //saving stdout fd int fdStdout = dup(1); int fdStdin = dup(0); char *test= "test"; if(pip0!=-1 && pip1!=-1){ //TODO: take from & put ot pipe } else if(pip0!=-1){ //there's something to read printf("in pipline function: read something\n"); char *tmp; read(pip0,tmp,100); //pipe(tpip); printf("on pipe: %s\n", tmp); //write(fdStdout, read(pip0,pipeArgs,10), 1000); printf("now reading from pipe\n"); //dup2(tpip[1], 1); //dup2(tpip[0], 0); dup2(pip0, 0); //parse pipeArgs an give them to run command //printf("%s\n", pipeArgs); run_command(args, argsNb, bg); //write(fdStdout, test, 100); close(pip0); dup2(fdStdin, 0); //close(tpip[0]); //close(tpip[1]); //dup2(fdStdin, 0); //dup2(fdStdout, 1); //printf("got from pipe: %s\n", pipeArgs); } else if(pip1!=-1){ // now redirect output to pipe printf("now start writing to pipe\n"); dup2(pip1,1); setvbuf(stdout,(char*)NULL,_IONBF,0); printf("------pipe starts here\n"); run_command(args, argsNb, bg); //int res = read(pip0, pipeArgs, 1000); //read from pipe //int res = read(pip0, pipeArgs, sizeof(pipeArgs)); //read from pipe //if (res == -1) return (error); //else printf("ok: reading from pipe\n"); printf("------pipe ends here\n"); //restore close(pip1); dup2(fdStdout,1); printf("writing back to stdout\n"); } else{ printf("in pipline function: no pipe\n"); run_command(args, argsNb, bg); } printf("exit of piplien fun\n"); return(0); }