打印宽字符以处理

时间:2019-06-24 23:50:12

标签: perl encoding stdin

我有一个perl脚本,它打开管道并执行第二个脚本。然后将冻结的对象打印到管道上。可以在一台计算机上运行,​​而不能在另一台计算机上运行。

正在运行的计算机正在运行Ubuntu 14.04,正在运行的计算机正在运行16.04。两台计算机上的语言环境相同:US.UTF-8

$frozenSelf = freeze($self);    
$childProcess  = open3( *CHILD_IN, *CHILD_OUT, ">&STDERR", 
"/usr/bin/perl $testcasePath/${testcaseFile}.pl" );
$selectHandIn  = IO::Select->new( \*CHILD_IN );
$selectHandOut = IO::Select->new( \*CHILD_OUT );
$selectHandErr = IO::Select->new( \*CHILD_ERR );
$selectHandIn->can_write(1);

print CHILD_IN $frozenSelf;
close(CHILD_IN)

while (<CHILD_OUT>)
{
    my $output = $_;
    print $output;
}

close(CHILD_ERR);
close(CHILD_OUT);

儿童脚本冻结的句柄:

    my @ready = IO::Select->new( \*STDIN )->can_read(1);
    my $stdin = @ready;
    if ($stdin)
    {
    $parentHandle = <STDIN>;
            if ( defined($parentHandle) )
            {
                    chomp $parentHandle;

                    # This call to thaw will cause a object destructor call
                    ($parentHandle) = thaw($parentHandle);
                    if ( !$parentHandle )
                    {
                            Error( undef, "Unable to thaw the parent Handle" );
                    }
                    $resultsPath = ( $parentHandle->{_resultsPath} ) . "/$scriptNameFull";
                    $instanceId = $parentHandle->{_instanceId};
                    $parentTestCase = $parentHandle->{_scriptNameFull};
                    $parentHandle->{_isClone} = 1;
            }
    }

在工作计算机上,冻结的对象被打印到手柄上,脚本继续进行。

在出现故障的计算机上,我收到了来自“ print CHILD_IN $ frozenSelf;”行的错误:

Wide character in print at
testcaseFile.pl line 1385 (#1)
(S utf8) Perl met a wide character (>255) when it wasn't expecting
one.  This warning is by default on for I/O (like print).  The easiest
way to quiet this warning is simply to add the :utf8 layer to the
output, e.g. binmode STDOUT, ':utf8'.  Another way to turn off the
warning is to add no warnings 'utf8'; but that is often closer to
cheating.  In general, you are supposed to explicitly mark the
filehandle with an encoding, see open and "binmode" in perlfunc.

我尝试在打印之前添加binmode CHILD_IN,':utf8',但这会产生以下错误:

Frozen string too short: `$14|​', expect 18 at 
/usr/share/perl5/FreezeThaw.pm line 374, <STDIN> line 1.
FreezeThaw::thawString called at /usr/share/perl5/FreezeThaw.pm line 533
FreezeThaw::thawScalar(1459) called at /usr/share/perl5/FreezeThaw.pm line 417
FreezeThaw::thawArray called at /usr/share/perl5/FreezeThaw.pm line 434
FreezeThaw::thawHash called at /usr/share/perl5/FreezeThaw.pm line 533
FreezeThaw::thawScalar(1294) called at /usr/share/perl5/FreezeThaw.pm line 417
...
FreezeThaw::thawScalar(30) called at /usr/share/perl5/FreezeThaw.pm line 833
    FreezeThaw::TCooky::ThawScalar(FreezeThaw::TCooky=SCALAR(0x536a2a0)) called at <testScript.pl> line 2503
    Framework::Thaw("Framework", FreezeThaw::TCooky=SCALAR(0x536a2a0)) called at /usr/share/perl5/FreezeThaw.pm line 860
    UNIVERSAL::Instantiate("Framework", HASH(0x1d28d08), FreezeThaw::TCooky=SCALAR(0x536a2a0)) called at /usr/share/perl5/FreezeThaw.pm line 564
    FreezeThaw::thawScalar(26, 0) called at /usr/share/perl5/FreezeThaw.pm line 722
    FreezeThaw::thaw("FrT;!0|{>0|\$9|Framework%0|})0|%102|\$12|_buildTested\$9|_caseLo"...) called at <testScript.pl>

有什么建议吗?

0 个答案:

没有答案