
我正在使用該tee
命令將程式的編譯錯誤與終端一起輸出到檔案中。
gcc hello.c | tee file.txt
這是我用過的命令。編譯錯誤會顯示在終端機上,但不會輸出到檔案。我應該如何將標準錯誤輸出到文件中?
答案1
使用csh
、tcsh
或zsh
最新版本的bash
,試試
gcc hello.c |& tee file.txt
在哪裡
- |& 指示 shell 將標準錯誤重新導向到標準輸出。
在其他類似 Bourne 的 shell 中:
gcc hello.c 2>&1 | tee file.txt
在rc
類別外殼中:
gcc hello.c >[2=1] | tee file.txt
在fish
外殼中:
gcc hello.c ^&1 | tee file.txt