0

If I have a program, its input and the desired output, how do I automate the comparison of what I want the program to give me and what it actually gives me? For example:

a=${./program < inputfile}
diff ${a} outputfile
1

diff takes filenames as arguments -- you passed the data from the stdout of the command, instead. If you're using bash, zsh, or another similar shell you can use process substition:

diff <(./program < inputfile) outputfile

Or, POSIXly (you can also use a named pipe, but it's probably overkill):

./program < inputfile > /tmp/program-out
diff /tmp/program-out outputfile
rm /tmp/program-out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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