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

标签 linux perl stdout

出于好奇,是否可以在 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

关于Linux/珀尔 : Additional output buffers other than STDOUT and STDERR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3347940/

相关文章:

linux - 测量 linux 内核从启动到用户空间所花费的时间

c++ - 在 Eclipse 中构建后没有二进制文件

arrays - 如何将简单(平面)数组转换为多维(2D)数组

C++ std::ofstream 类成员

java - 在两台相连的计算机之间发送数据包的最快方法?

c - Linux 中 printf ("\n...") 和 printf ("..\n") 之间的输出差异

ruby - Sed 或 Perl : One file with regex instructions, 每行一条指令,在另一个文件上执行

perl 脚本中的 javascript

bash - 在 Bash 中连接字符串、文件和程序输出

bash - 如何将 CMake 输出保存到文件?