这个程序时在展讯的编译过程中用到的,查了一下才知道是干什么用的。

------------------------------------------------------------------------------

tee
一个linux下把数据同时写到屏幕和文档的常用工具
标题里面写屏幕是便于理解 其实就是写到标准输出
read from standard input and write to standard output and files
一个常用的参数是 -a
-a, --append
append to the given FILEs, do not overwrite
就是说不覆盖文档 而是追加到文档。

------------------------------------------------------------------------------

实验一下:

在命令行中输入以下命令

echo hello|tee -a my.txt

运行后,屏幕显示hello,然后当前目录会有有个my.txt文件生成,里面也有个hello。

这就是它的作用,把应用程序的输出同时送到屏幕和文件里,通常用于产生log。

实际使用时,发现出错的提示不会打印到log文件里,因为tee只接收标准输出(stdout),出错的提示一般打印到标准错误输出(stderr),所以窗口显示了错误输出,但log文件里没有。

例如:屏幕显示:

一般输出信息1。
错误输出信息1。
一般输出信息2。
一般输出信息3。
错误输出信息2。
一般输出信息4。

到了log文件里,只有:

一般输出信息1。
一般输出信息2。
一般输出信息3。
一般输出信息4。

需要把stderr重定向到stdout:

echo hello 2>&1|tee -a my.log

这样屏幕上显示的都写到log里了。

Logo

更多推荐