输出重定向

Wil*_*ire 1 command-line pipe io-redirection tee

我正在使用该tee命令将程序的编译错误与终端一起输出到文件中。

gcc hello.c | tee file.txt 
Run Code Online (Sandbox Code Playgroud)

这是我用过的命令。编译错误显示在终端上,但不会输出到文件中。我应该如何将 std 错误输出到文件中?

Arc*_*mar 5

随着cshtcshzsh或最新版本bash,尝试

gcc hello.c |& tee file.txt
Run Code Online (Sandbox Code Playgroud)

在哪里

  • |& 指示 shell 将标准错误重定向到标准输出。

在其他类似 Bourne 的 shell 中:

gcc hello.c 2>&1 | tee file.txt
Run Code Online (Sandbox Code Playgroud)

rc--like shell:

gcc hello.c >[2=1] | tee file.txt
Run Code Online (Sandbox Code Playgroud)

fish外壳中:

gcc hello.c ^&1 | tee file.txt
Run Code Online (Sandbox Code Playgroud)