1

入力ファイルと出力ファイル (test.in と test.out) があり、標準入力が test.in から来るようにリダイレクトされたプログラム "./myprogram" があり、標準出力からキャプチャされた結果を使用して比較するとします。 test.out で

どのように正確に比較できますか

考えている、

 if [ $(myprogram < test.in) == $(cat test.out) ]

助言がありますか?

4

2 に答える 2

4

cmpを使用-して、比較するファイルの 1 つとして指定します。これにより、stdin を使用するように指示されます。

if myprogram < test.in | cmp -s - test.out; then

一時ファイルを作成せずに 2 つのコマンドの出力を比較する場合は、この機能を使用し<(cmd)ます。( で「プロセス置換」を検索してman bashください。)

if cmp -s <(myprogram < test1.in) <(myprogram < test2.in); then

またはdiff、違いを知りたい場合。

于 2012-10-01T01:46:26.580 に答える
0

私は差分を使用します。このようなもの:

if cat test.in | myprogram | diff - test.out

于 2012-10-01T01:56:14.740 に答える