简体   繁体   English

如何保存包含混合ascii内容的Perl / Expect输出?

[英]How can I save Perl/Expect output that contains mixed ascii content?

I have a perl script that uses the expect library to login to a remote system. 我有一个Perl脚本,该脚本使用Expect库登录到远程系统。 I'm getting the final output of the interaction with the before method: 我正在使用before方法获得交互的最终输出:

$exp->before();

I'm saving this to a text file. 我将其保存到文本文件。 When I use cat on the file it outputs fine in the terminal, but when I open the text file in an editor or try to process it the formatting is bizarre: 当我在文件上使用cat时,它在终端上的输出效果很好,但是当我在编辑器中打开文本文件或尝试对其进行处理时,格式却很奇怪:

[H[2J[1;19HCIRCULATION ACTIVITY by TERMINAL (Nov 6,14)[11;1H [H [2J [1; 19; H循环活动由终端(11月6,14)[11; 1H

Is there a better way to save the output? 有没有更好的方法来保存输出?

When I run enca it's identified as: 当我运行enca时,它被标识为:

7bit ASCII characters 7位ASCII字符

Surrounded by/intermixed with non-text data 被非文本数据包围/混合

you can remove none ascii chars. 您不能删除任何ASCII字符。

$str1 =~ s/[^[:ascii:]]//g;
print "$str1\n";

I was able to remove the ANSI escape codes from my output by using the Text::ANSI::Util library's ta_strip() function: 我可以使用Text :: ANSI :: Util库的ta_strip()函数从输出中删除ANSI转义代码:

my $ansi_string = $exp->before();
my $clean_string = ta_strip($ansi_string);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM