I have this old piping program example...maybe you'll get something out of it.
Usage ./filename ps wc
will pipe the output of ps into wc
#include <unistd.h>
enum PIPES {READ, WRITE};
int main(int argc, char**argv)
{
if (argv[2])
{
int hpipe[2];
pipe(hpipe);
if (fork())
{
close (hpipe[WRITE]);
dup2 (hpipe[READ], 0);
close (hpipe[READ]);
execlp (argv[2],argv[2],NULL);
}
else
{
close (hpipe[READ]);
dup2 (hpipe[WRITE], 1);
close (hpipe[WRITE]);
execlp (argv[1],argv[1],NULL);
}
}
return 0;
}
Reputation Points: 499
Solved Threads: 367
Postaholic
Online 2,198 posts
since Jan 2008