My linux world » Perl – Read Pipe

Perl - Read Pipe


# open pipe
open(MYPIPE,"<ls -la |") or die "Fail to open pipe\n";
 
# read each line of the pipe. Each line is available in $_
while(<MYPIPE>) 
{ 
  # avoid \n on last field
  chomp $_;
 
  my $line = $_;
}
 
# close pipe
close(MYPIPE);

Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.