【发布时间】:2011-03-15 15:06:42
【问题描述】:
我在 Perl 中执行的系统命令的输出是否有文件句柄/句柄?
【问题讨论】:
标签: perl ipc pipe stdio filehandle
我在 Perl 中执行的系统命令的输出是否有文件句柄/句柄?
【问题讨论】:
标签: perl ipc pipe stdio filehandle
【讨论】:
open 陈旧而笨拙(并且有潜在危险)。 Use the three-arg version instead
这是在脚本和其他命令之间建立管道的示例,使用 open 的 3 参数形式:
open(my $incoming_pipe, '-|', 'ls -l') or die $!;
open(my $outgoing_pipe, '|-', "grep -v '[02468]'") or die $!;
my @listing = <$incoming_pipe>; # Lines from output of ls -l
print $outgoing_pipe "$_\n" for 1 .. 50; # 1 3 5 7 9 11 ...
【讨论】: