Perl中的输出流:STDERR,STDOUT,

前端之家收集整理的这篇文章主要介绍了Perl中的输出流:STDERR,STDOUT,前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Linux/Perl: Additional output buffers other than STDOUT and STDERR?                                    1个
我知道输出流STDOUT和STDERR.每当你打印到STDOUT时,在unix shell中你可以像这样重定向输出……

deviolog@home:~$perl test_script.pl > output.txt

要么

deviolog@home:~$perl test_script.pl 1> output.txt

当您打印到STDERR时,它看起来相同,但您切换到“频道”(?)编号2:

deviolog@home:~$perl test_script.pl 2> output.txt

我可以在output.txt中找到我当时正在打印的错误输出.

我的问题是,我可以以某种方式访问​​“频道”3号吗?
有什么像……

print STDX "Hello World!\n";

…允许重定向,如下所示?

deviolog@home:~$perl test_script.pl 3> output.txt

附:一个子问题将是那些“渠道”^ _ ^的术语

解决方法

您可以使用open,append& =为模式创建一个打开文件描述符(fd)的Perl文件句柄,并使用文件描述符作为文件名.在您的情况下,您将使用以下内容

open(my $fh,'>&=',3)

例如,

$perl -E'
   open(my $fh,">&=",3) or die $!;
   say fileno($fh);
   say $fh "meow";
' 3>output.txt
3

$cat output.txt
meow

猜你在找的Perl相关文章