出于好奇,是否可以在Perl脚本中创建,实例化或以其他方式访问STDOUT和STDERR之外的其他输出缓冲区?
用例将是附加输出,用于传递到文件或其他命令,例如./doublerainbow.pl 3>full_on.txt 4>all_the_way!.txt
绝对。 open
模式的>&=
命令允许您在任意文件描述符上打开文件句柄。
# perl 4fd.pl > file1 2> file2 3> file3 4> file4 5< file5
open NONSTDFOO, '>&=3';
open NONSTDBAR, '>&=4';
open NONSTDBAZ, '<&=5'; # works for input handles, too
print STDOUT "hello\n";
print STDERR "world\n";
print NONSTDFOO "42\n";
print NONSTDBAR <NONSTDBAZ>;
$ 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