R
ramasubramanian.rahul
i am trying to implement the unix command ls -l | wc -l
in c...( using pipes and excev)
its not working.... can anyone help me here ???
thanks in advance
rahul
#include<stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 int main()
5 {
6 int a[2] , test ;
7 pipe(a);
8 close(0);
9 dup2(a[0],0);
10 if (fork() == 0)
11 {
12 close(1) ;
13 dup2(a[1] ,1);
14 close(a[1]);
15 close(a[0]);
16 close(a[0]);
17 execlp("/bin/ls" , "ls" , "-a" , NULL );
18 }
19 else
20 {
21
22 wait (NULL);
23 execlp("/usr/bin/wc" , "wc" , "-l" );
24 }
25 }
in c...( using pipes and excev)
its not working.... can anyone help me here ???
thanks in advance
rahul
#include<stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 int main()
5 {
6 int a[2] , test ;
7 pipe(a);
8 close(0);
9 dup2(a[0],0);
10 if (fork() == 0)
11 {
12 close(1) ;
13 dup2(a[1] ,1);
14 close(a[1]);
15 close(a[0]);
16 close(a[0]);
17 execlp("/bin/ls" , "ls" , "-a" , NULL );
18 }
19 else
20 {
21
22 wait (NULL);
23 execlp("/usr/bin/wc" , "wc" , "-l" );
24 }
25 }