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 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <stdio.h>
#include <memory.h>
#include <unistd.h>
int main( int argc, char ** argv )
{
char buffer[BUFSIZ+1];
/* create the pipe */
int pfd[2];
if (pipe(pfd) == -1)
{
printf("pipe failed\n");
return 1;
}
/* create the child */
int pid;
if ((pid = fork()) < 0)
{
printf("fork failed\n");
return 2;
}
if (pid == 0)
{
/* child */
close(pfd[1]); /* close the unused write side */
// dup2(pfd[0], 0); /* connect the read side with stdin */
read(pfd[0], buffer, BUFSIZ);
close(pfd[0]); /* close the read side */
/* execute the process (wc command) */
// execlp("wc", "wc", (char *) 0);
// printf("wc failed"); /* if execlp returns, it's an error */
// return 3;
printf("%s", buffer);
}
else
{
/* parent */
close(pfd[0]); /* close the unused read side */
dup2(pfd[1], 1); /* connect the write side with stdout */
close(pfd[1]); /* close the write side */
/* execute the process (ls command) */
execlp("/data/data/com.galoula.Privoxy/bin/dnslookup", "/data/data/com.galoula.Privoxy/bin/dnslookup", "2", "www.Galoula.com", (char *)0);
printf("ls failed"); /* if execlp returns, it's an error */
return 4;
}
return 0;
} |
Partager