繁体   English   中英

当输入重定向到文件时,如何比较两个二进制文件的输出?

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

我有两个编译的C文件,我试图在shell脚本中进行比较,看看当两者的输入被重定向到另一个名为test.txt的文件时它们是否产生相同的输出。 我必须确保我的代码执行以下操作:

但是,我不认为我的代码是正确的。 我认为我遗漏了有关输入重定向部分的内容。

这是我到目前为止:

#!/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

你有几个错误,试试这个:

#!/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.

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