Win32 :: Console和STDOUT [英] Win32::Console and STDOUT

查看:194
本文介绍了Win32 :: Console和STDOUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 包MY_TEST; 
使用警告;
use strict;
使用Win32 :: Console;

my $ out = Win32 :: Console-> new(STD_OUTPUT_HANDLE);

sub test_print {
$ out-> Write(printed with'Write'\);
print(printed with'print'\);
}

当我用这个脚本调用这个包时

 #!/ usr / bin / env perl 
使用警告;
use strict;
use 5.10.0;
使用FindBin qw($ RealBin);
使用MY_TEST;

say'Beforetest_print';
MY_TEST :: test_print;
say'Aftertest_print';

输出如下所示

 在test_print之前
打印'write'
打印'print'
在test_print之后
/ pre>

但是当我注释行时

 #$ out-> Write(printed with'Write'\); 

输出为空。



为什么删除写入行会阻止打印 print lines?

解决方案

只是一个猜测,但它可能需要刷新缓冲区。 Write()可能会这样做,而 print()自然不会。


package MY_TEST;
use warnings;
use strict;
use Win32::Console;

my $out = Win32::Console->new( STD_OUTPUT_HANDLE );

sub test_print {
    $out->Write( "printed with 'Write'\n" );
    print( "printed with 'print'\n" );
}

When I call this package with this script

#!/usr/bin/env perl
use warnings;
use strict;
use 5.10.0;
use FindBin qw($RealBin);
use MY_TEST;

say 'Before "test_print"';
MY_TEST::test_print;
say 'After "test_print"';

the output looks like this

Before "test_print"
printed with 'Write'
printed with 'print'
After "test_print"

But when I comment the Write line out

# $out->Write( "printed with 'Write'\n" );

the output is empty.

Why does removing the Write line prevent printing the print lines?

解决方案

Just a guess, but it could be related to needing to flush the buffer. Write() might do it while print() naturally will not.

这篇关于Win32 :: Console和STDOUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆