【发布时间】:2013-09-15 11:56:36
【问题描述】:
我制作了一个基本上是解释器的玩具交互式控制台程序:
$ myprogram
> this is user input
this is program output
我想将整个会话(包括用户输入和程序输出)通过管道传输到日志文件中。我可以这样做:
$ cat | tee >(myprogram | tee -a file.log) >> file.log
> this is user input
this is program output
$ cat file.log
> this is user input
this is program output
所以上面的会话会像往常一样显示在终端上,但也会复制到日志文件中。
有没有更好的方法来做到这一点?我不喜欢我必须两次写入日志文件,也不喜欢在运行此命令之前必须记得擦除它。
【问题讨论】:
-
Tee 命令用于将输出重定向到文件。基本上,如果您编写 $output | 它会将您的输出复制到文件中。 tee file.log 它将输出复制到 file.log