I am looking for a method to pull input into my program from either a Pipe from the terminal or by specifing a filename as an argument. Effectivly
1. foo | myprogram
OR
2. foo > bar; myprogram -w bar
The second operation is accoplished simply by reading the file. However I am drawing a blank on how to redirect the output from foo into myprogram with a pipe. In all the examples I have managed to find Pipes have been used almost exclusively for IPC from parent to child processes. Am I thinking of the proper Pipe or is this a different mechanism?
I also realize that when foo | myprogram is executed the programs are executed simulatniously. How is this handled if foo is read in continuously.
EDIT:
Forgot to include this:
int main(){
char buff[255];
int i = read(0, buff, 255);
printf("Debug: %s\n", buff);
return 0;
}
If for instance I execute ls | myprogram I tend to receive.
. ../ files
Debug:
instead of
Debug: . ../ files
You can do something like this: