可以彩色输出通过shell重定向被捕获? [英] Can colorized output be captured via shell redirect?
问题描述
我使用各种庆典命令 - 花哨的diff,建立脚本等,产生大量的彩色输出
Various bash commands I use -- fancy diffs, build scripts, etc, produce lots of color output.
当我将此输出重定向到一个文件,然后猫
或少
文件后,彩色化走了 - presumably b / C输出重定向行为剥离出来的颜色codeS,告诉终端改变颜色
When I redirect this output to a file, and then cat
or less
the file later, the colorization is gone -- presumably b/c the act of redirecting the output stripped out the color codes that tell the terminal to change colors.
有没有一种方法来捕捉彩色输出,包括着色?
Is there a way to capture colorized output, including the colorization?
推荐答案
一捕捉到彩色输出的方法是使用剧本
命令。运行剧本
开始,所有的原始输出被捕获到一个文件中的bash命令(名为打字稿
默认情况下)
One way to capture colorized output is with the script
command. Running script
will start a bash session where all of the raw output is captured to a file (named typescript
by default).
这篇关于可以彩色输出通过shell重定向被捕获?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!