输出到 STDERR 是否通常不解码



当我运行这个脚本(或使用DBD::SQLite或DBD::MySQL的类似脚本)时,看起来返回的错误消息没有被解码。
STDERR的输出通常不解码吗?

#!/usr/bin/env perl
use warnings;
use strict;
use utf8;
use open qw( :encoding(UTF-8) :std );
use DBI;
my $dbh = DBI->connect( "DBI:Pg:dbname=my_test_db", 'username', 'password', {
    PrintError => 0,
    RaiseError => 1,
    AutoCommit => 1,
    pg_enable_utf8 => 1,
} ) or die DBI->errstr;
my $sth = $dbh->prepare( "S☺LECT * FROM abteilung" );
$sth->execute();

输出:

#DBD::Pg::st execute failed: FEHLER:  Syntaxfehler bei »SâºLECT«
#ZEILE 1: SâºLECT * FROM abteilung
#         ^ at ./perl2.pl line 16.

这可能是双重编码的情况。驱动程序使用 UTF-8 对查询进行编码,然后将该查询包含在错误消息中,然后(正确)编码以进行输出。

最新更新