1

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?

1
  • this works when you use the right syntax to pipe output of one program (file) to another program (test) which will have it available as input... if you want to handle pipes programmatically, under POSIX systems you can use (in test) popen and let it open and execute "file" for you (popen returns a FILE * "representing" the output of file). Commented Apr 8, 2012 at 20:45

1 Answer 1

3

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 command

./file > ./test 

runs the program file and creates a new file test that contains the output from file. It does not run a program called test, and in fact it will overwrite one if it exists.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.