I have a perl script
which runs a bunch of commands redirects both stdin
and stderr
into a text file. After the scripts finish, I display the contents of the file to a webpage that invoked it, using cgi.
At least one of the lines wrote to the file contains wide characters, such as:
Saving to: ârabbitmq-server-3.3.5-1.noarch.rpmâ
I've tried to html escape the file when outputting to the webpage, but to no avail:
use CGI;
.
.
.
my $filename = 'tempoutput.txt';
open(my $fh, '<:encoding(UTF-8)', $filename)
or die "Could not open file '$filename' $!";
while (my $row = <$fh>) {
chomp $row;
print $cgi->p("");
print $cgi->escapeHTML("$row");
}
I've also tried changing CGI's param which I found in a google, but it also didn't work.
use CGI '-utf8';
Any ideas on what I need to do to make this work?
Turn on support for UTF8 printing with
binmode STDOUT, ":utf8";
.