0

How can we redirect both stdin and stderr in shorter way? please correct me if the below method is wrong. Also suggest me any other way to do it at once.

command <file1.txt 2>file2.txt
4

3 回答 3

4

If you really mean stdin and stderr I don't think there's a "shorter way"; even if there was some syntax sugar for this (quite unlikely), your example shows that you want to make use of different files, so you should explicitly specify each redirection anyhow...

However, for stdout and stderr (if you want those redirected to the same file), you can type:

command &> file.txt
于 2013-06-27T22:50:43.353 回答
3

The way you're doing it is correct. You can't redirect both stdin and stderr to the same file. You can redirect stdout and stderr to the same file, though:

command >file.txt 2>&1
于 2013-06-27T22:49:31.390 回答
0

There really isn't a "shorter" way per se (I assume by shorter you mean fewer characters) .
However, as an alternative you could use:

cat file1.txt | command 2> file2.txt
于 2013-06-27T22:55:57.707 回答