I am writing a program that processes the output of another program.
Assume my testing program is called test and I want to process the stdout output of program named file.
In test, I am reading stdin as a file as follows:
FILE *fp;
fp = fopen("/dev/stdin", "r");
This works when I run the following in command line: ./file | ./test.
But I assume I want to use I/O redirection, so: ./file > ./test. How can I handle that in C?
I/O redirection using
>is not for piping output from one program into another program. It redirects the output from one program into a file. The commandruns the program
fileand creates a new filetestthat contains the output fromfile. It does not run a program calledtest, and in fact it will overwrite one if it exists.