I have a program that writes to stdout. Is there a way that I can redirect the output to the linux diff command or do I have to write the output to a file and then compare that. For example I have a bunch of test input files for a program and the corresponding expected output in another set of files. And I'd like to do something like ./program < t1.input | diff t1.expected.

link|improve this question
feedback

3 Answers

up vote 2 down vote accepted

You can also do this:

./program < t1.input | diff t1.expected -
link|improve this answer
feedback

In bash:

diff t1.expected <(./program < t1.input)
link|improve this answer
Do you know of anyway to do that straight from a linux command line? When I try what you posted I get "Missing name for redirection." – blcArmadillo Jan 13 '11 at 22:10
Stop putting extra spaces. – Ignacio Vazquez-Abrams Jan 13 '11 at 22:23
What do you mean by extra spaces? – blcArmadillo Jan 13 '11 at 22:32
You have a space between the < and the (. Don't do that. – Ignacio Vazquez-Abrams Jan 13 '11 at 22:32
feedback

In case you want to diff two outputs of programs, zsh is your friend:

$ diff =(program1 < input1) =(program2 < input2)
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.