Gray
Gray

Reputation: 413

How to compare the output of two binary files when the input is redirected to a file?

I have two compiled C files that I am trying to compare in a shell script to see if they produce the same output when the input for both is redirected to another file called test.txt. I have to make sure my code does the following:

However, I don't think that my code is correct. I think that I'm missing something regarding the input redirection part.

This is what I have so far:

#!/usr/bin/env bash

if [ -e test-code ] 
then
    ./test-code > test1.txt 
    ./gold-code > test2.txt
    diff -w test1.txt test2.txt < test.txt

    if [ $? -eq 0 ]
    then
        exit 0
    fi
else
    exit 1
fi

Upvotes: 1

Views: 125

Answers (1)

Uprooted
Uprooted

Reputation: 971

You have several errors, try this:

#!/usr/bin/env bash

set -e # every command that fails does exit $?
[ -e test-code ] 
./test-code < test.txt > test1.txt 
./gold-code < test.txt > test2.txt
diff -w test1.txt test2.txt

Upvotes: 3

Related Questions