Linux/Perl: Additional output buffers other than STDOUT and STDERR?

耗尽温柔 提交于 2019-11-30 13:43:20
mob

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!