tee和脚本本质上是等效的吗? [英] Are tee and script essentially equivalent?
问题描述
在我要捕获文件中进程的 stdout 但仍要在终端中显示此输出的情况下,我可以在script
和tee
之间进行选择.在这种情况下,这些工具在本质上是等效的,还是有(可能是微妙的)理由偏爱一种?
程序script
和tee
被设计用于不同的目的:
-
script
-制作终端会话的打字稿 -
tee
-管道配件
script
和tee
之间的重要区别是:
-
script
传送它所监视的进程的退出状态,而tee
作为过滤器甚至不知道它. -
script
捕获其监视的进程的 stdin , stdout , stderr ,而tee
仅捕获其过滤的流.
在给定的上下文中,这些差异均不相关.
我发现script
对于使控制序列在输送到tee
时起作用非常有用:
script -q -c 'python -c "import pdb, sys; pdb.set_trace()"' /dev/null \
| tee -a /tmp/tmp.txt
仅使用以下内容,Ctrl-A
将显示为^A
等:
python -c "import pdb, sys; pdb.set_trace()" | tee -a /tmp/tmp.txt
这是一个最小的示例.我在这里使用tee
来捕获pytest测试运行的输出,但有时其中可能存在调试器,然后光标键等应该可以工作.
通过 https://unix.stackexchange.com/a/61833/1920 .
In the context where I want to capture the stdout of a process in a file but still want to have this output displayed in the terminal I can choose between script
and tee
. In this context, are these tools essentially equivalent or is there a – possibly subtle – reason to prefer one over the other?
The programs script
and tee
are designed for different purposes:
script
-- make typescript of terminal sessiontee
-- pipe fitting
Important differences between script
and tee
are:
script
transmits the exit status of the process it supervises, whiletee
, being a filter, does not even know about it.script
captures stdin, stdout, stderr of the process it supervises whiletee
only catches the stream it filters.
None of these differences are relevant in the given context.
I found script
to be useful for making control sequences work when piping to tee
:
script -q -c 'python -c "import pdb, sys; pdb.set_trace()"' /dev/null \
| tee -a /tmp/tmp.txt
With only the following, Ctrl-A
would be displayed as ^A
etc:
python -c "import pdb, sys; pdb.set_trace()" | tee -a /tmp/tmp.txt
This is a minimal example. I am using tee
here to capture the output from a pytest test run, but sometimes there might be a debugger in there, and cursor keys etc should work then.
Via https://unix.stackexchange.com/a/61833/1920.
这篇关于tee和脚本本质上是等效的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!