Linux/Perl:除STDOUT和STDERR之外的其他输出缓冲区? [英] Linux/Perl: Additional output buffers other than STDOUT and STDERR?

查看:85
本文介绍了Linux/Perl:除STDOUT和STDERR之外的其他输出缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇,是否可以在Perl脚本中创建,实例化或以其他方式访问STDOUT和STDERR之外的其他输出缓冲区?

Out of curiosity, is it possible to create, instantiate, or otherwise access additional output buffers besides STDOUT and STDERR from within a Perl script?

用例将是附加输出,以管道传输到文件或其他命令,例如./doublerainbow.pl 3>full_on.txt 4>all_the_way!.txt

The use case would be additional outputs to pipe in to files or other commands, eg ./doublerainbow.pl 3>full_on.txt 4>all_the_way!.txt

推荐答案

绝对. open模式下的open命令允许您在任意文件描述符上打开文件句柄.

Absolutely. The open command with the >&= mode allows you to open filehandles on arbitrary file descriptors.

# perl 4fd.pl > file1 2> file2 3> file3 4> file4 5< file5

open STDFOO, '>&=3';
open STDBAR, '>&=4';
open STDBAZ, '<&=5';   # works for input handles, too

print STDOUT "hello\n";
print STDERR "world\n";
print STDFOO "42\n";
print STDBAR <STDBAZ>;


$ echo pppbbbttt > file5
$ perl 4fd.pl >file1 2>file2 3>file3 4>file4 5<file5
$ cat file1
hello
$ cat file3
42
$ cat file4 file2
pppbbbttt
world

这篇关于Linux/Perl:除STDOUT和STDERR之外的其他输出缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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