当前位置: 传客网 > perl open多个管道的管道

perl open多个管道的管道

2016-12-30 作者:Manfred

1,将多个管道的数据读进perl文件句柄
use IPC::Open2;
my ($fh,$ffh);
my $pid=open2($fh,$ffh,"seq 1 20 |tail -n 15 ") or die "Cannot open pipe:$!";
while(<$fh>){
     chomp;
     print $_,"\t",$.,"\n";
 }
注意:显示的单引号其实都是双引号。
2,将数据作为输入,到多个管道命令
use IPC::Open2;
my ($fh,$ffh);
my @aa=(1..10);
my $pid=open2 $fh,$ffh," sort -bnr |tail -n 5 >pipe.out" or die "Cannot open pipe\n";
for (@aa){
    $_.="\n";
    print $ffh $_;
}

  NAME

   IPC::Open2, open2 - open a process for both reading and writing

 SYNOPSIS


    use IPC::Open2;

    ;
      # or without using the shell

    ;

    # or with handle autovivification 

my;
    ;
      # or without using the shell 

     ;
http://www-rohan.sdsu.edu/doc/perldoc-html/IPC/Open2.html


相关推荐

返回
顶部