簡體   English   中英

打印STDOUT / STDERR並將它們寫入Bash中的文件?

[英]Print STDOUT/STDERR and write them to a file in Bash?

有沒有辦法讓Bash將STDOUT / STDERR重定向到一個文件,但仍然將它們打印到終端?

這會將STDOUT和STDERR重定向到同一個文件:

some_command 2>&1 | tee file.log

$ touch foo; ls foo asfdsafsadf 2>&1 | tee file.log
ls: asfdsafsadf: No such file or directory
foo
$ cat file.log
ls: asfdsafsadf: No such file or directory
foo

使用tee命令。

$ echo "hi" | tee output.txt
hi
[unix]$ ls
output.txt
[unix]$ cat output.txt 
hi

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM