存储脚本输出时删除 ANSI 代码
有些程序使用 ANSI 转义序列制作漂亮的进度条和东西。那很好。
但不好的是,如果我将这种程序的输出放入一个文件中,然后尝试查看它,它就会充满奇怪的转义序列。
有没有办法在记录时去掉所有 ANSI 代码?
我通常这样记录脚本的输出:
./script >> /tmp/output.log
Some programs makes beautiful progressbars and stuff using ANSI escape sequences. That's nice.
What's not nice though is that if i put the output of that kind of program into a file and then try to view it it's filled with strange escape sequences.
Is there a way to strip away all the ANSI codes while logging?
I usually log the output of a script this way:
./script >> /tmp/output.log
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
如果这不起作用,那是因为 ANSI 代码已被硬编码到脚本中,因此没有简单的方法可以删除它们。如果确实如此,那是因为它正在做正确的事情,将诸如漂亮输出之类的事情委托给 libncurses 或类似的东西,这样当您更改 TERM 变量时,库就不再发送那些代码。
Try:
If that doesn't work, it's because the ANSI codes have been hard-coded into the script, so there is no easy way to remove them. If it does, it's because it's doing the right thing, delegating things like pretty output to
libncurses
or similar, so that when you change theTERM
variable, the library no longer sends those codes.使用
ansifilter
:use
ansifilter
: