[英]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. 我有两个编译的C文件,我试图在shell脚本中进行比较,看看当两者的输入被重定向到另一个名为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
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.