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?
popenand let it open and execute "file" for you (popen returns aFILE *"representing" the output offile).