Home > development > Consuming pipe Inputs in Unix

Consuming pipe Inputs in Unix

You’d like your application to read pipe inputs, like “ls -la | myGreatApp”? That’s pretty easy:

#include <stdio.h>
#include <unistd.h>
 
int main(void)
{
  char input[BUFSIZ];
  /* just read it ... */
  read(STDIN_FILENO, input, BUFSIZ);
  /* ... and use it */
  puts(input);
 
  return(0);
}
Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.