簡體   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