管道交互式会话到一个文件 [英] Piping an interactive session to a file
本文介绍了管道交互式会话到一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经做了玩具的互动控制台程序,基本上是一个跨preTER:
I have made a toy interactive console program that is basically an interpreter:
$ myprogram
> this is user input
this is program output
欲管完全会话,无论用户输入和程序输出,到日志文件中。我能做到这一点,像这样:
I want to pipe the full session, both user input and program output, into a log file. I can do this like so:
$ 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
因此上述会议将显示到终端如常,但也将被复制到日志文件。
So the above session will display to the terminal as usual but will also be duplicated to the log file.
有没有更好的方法来做到这一点?我不喜欢我怎么也得写日志文件两次,我也怎么也得记住运行此命令之前擦拭。
Is there a better way to do this? I don't like how I have to write the log file twice, nor how I have to remember to wipe it before running this command.
推荐答案
在简单的形式可能是
tee >(myprogram) | tee -a file.log
如果您想prevent输入被再次显示到屏幕上:
If you want to prevent input being shown again to the screen:
tee -a file.log | myprogram | tee -a file.log
这篇关于管道交互式会话到一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文