Win32 :: Console和STDOUT [英] Win32::Console and STDOUT
本文介绍了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之前
/ pre>
打印'write'
打印'print'
在test_print之后
但是当我注释
写
行时#$ out-> Write(printed with'Write'\);
输出为空。
为什么删除
写入
行会阻止打印解决方案只是一个猜测,但它可能需要刷新缓冲区。
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解决方案Just a guess, but it could be related to needing to flush the buffer.
Write()
might do it whileprint()
naturally will not.这篇关于Win32 :: Console和STDOUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文