1

Under Linux/bash I want to run a command and send standard output to foo.txt as well as combined standard output and standard error to bar.txt:

$ cmd < input.txt  1>foo.txt 1+2>bar.txt   ???

What's the easiest way to do this?

To send just stdout is:

$ cmd > foo.txt

To send both stdout/stderr is:

$ cmd &> bar.txt

However trying to combine:

$ cmd > foo.txt &>bar.txt

Causes foo.txt to be empty.

4

2 に答える 2

1

出力ストリームの 2 つのリダイレクトを同時に行うことはできません。必要なことを行う最も簡単な方法は、出力をteeコマンドにパイプすることです。

于 2013-02-28T09:15:04.527 に答える
1

次のようにする必要があります。

(cmd | tee out.txt) &> both.txt

と の両方とにリダイレクトさstdoutれます。out.txtstdoutstderrboth.txt

于 2013-02-28T09:16:22.117 に答える