Tessa
Tessa

Reputation: 137

Redirect stdin and stdout in terminal to test program

I have a program that reads from stdin and outputs to stdout. I would like to be able to test this via the terminal.

I know that

./program < input_file       # Redirects stdin

./program > output_file      # Redirects stdout

output_file < ./program < input_file # Is this supposed to redirect stdin and stdout at the same time?

What if I have sample output in test.out that I want to compare output_file with? How can I do this in one go?

I have tried various ways of doing this, but no luck so far.

Upvotes: 0

Views: 447

Answers (1)

Barmar
Barmar

Reputation: 782320

You have the redirection to the output file wrong. You need to use >, not <, and it has to go before the filename. Just like in your second example -- it's no different when you're redirecting both input and output.

./program < input_file > output_file

What you wrote says to run the program named output_file, and redirect its input first from ./program and then from input_file.

Upvotes: 1

Related Questions