-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.c
More file actions
36 lines (26 loc) · 705 Bytes
/
pipe.c
File metadata and controls
36 lines (26 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "headers.h"
void piper( char ** pipeSeperatedInput){
int countOfCommand=0;
for(int i=0; pipeSeperatedInput[i]!=NULL;i++){
countOfCommand++;
}
if(!countOfCommand){
return;
}
if(countOfCommand==1){
redirectHandler(pipeSeperatedInput[0],0,1);
}
else{
int fides[2],input=0;
for(int i=0;i<countOfCommand;i++){
if(i==countOfCommand-1){
redirectHandler(pipeSeperatedInput[i],input,1);
return;
}
pipe(fides);
redirectHandler(pipeSeperatedInput[i],input,fides[1]);
close(fides[1]);
input=fides[0];
}
}
}