简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM