I try to edit my post, since there were some issues with it.
I am still lost, trying to multipipe my program. When I run the program, goes into a state where it just takes some input - a like, perhaps its because I am not getting input to the second program in my piping process.
I have tried to follow the code from this post: Does this multiple pipes code in C makes sense?
My code looks like this:
int status;
int newpipe[2];
int oldpipe[2];
pid_t pid;
int countcmds = 0;
while (firstCmd != NULL) {
printf("En iteration \n");
if (firstCmd -> next != NULL) {
pipe(newpipe);
}
pid = fork();
if(pid == 0){
if (firstCmd -> prev != NULL) {
dup2(oldpipe[0],0);
close(oldpipe[0]);
close(oldpipe[1]);
}
if (firstCmd -> next != NULL) {
close(newpipe[0]);
dup2(newpipe[1],1);
close(newpipe[1]);
}
char** file = firstCmd -> cmd;
char* specfile = *file;
execvp(specfile, file);
}
else{
waitpid(pid, &status, 0);
if (firstCmd -> prev != NULL) {
close(oldpipe[0]);
close(oldpipe[1]);
}
if(firstCmd -> next != NULL){
oldpipe[0] = newpipe[0];
oldpipe[1] = newpipe[1];
}
countcmds++;
firstCmd = firstCmd -> next;
}
}
if(countcmds){
close(oldpipe[0]);
close(oldpipe[1]);
}