2010-07-14 6 views

답변

1

예,이 같은 파이프를 사용할 수 있습니다

open(my $pipe, "ls|") or die "Cannot open process: $!"; 
while (<$pipe>) { 
    print; 
} 

파이프 동작에 대한 자세한 설명은 perlipc을 자세한 내용은 open의 문서를 참조하십시오.

+4

두 인수'open'이 과거와 crufty (그리고 잠재적으로 위험한)입니다. [3 인수 버전을 대신 사용하십시오] (http://www.modernperlbooks.com/mt/2010/04/three-arg-open-migrating-to-modern-perl.html) – Daenyth

12

여기 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 ...