简体   繁体   中英

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. I'm getting the final output of the interaction with the before method:

$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:

[H[2J[1;19HCIRCULATION ACTIVITY by TERMINAL (Nov 6,14)[11;1H

Is there a better way to save the output?

When I run enca it's identified as:

7bit ASCII characters

Surrounded by/intermixed with non-text data

you can remove none ascii chars.

$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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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