2

E.g.
- $stream1 is the STDOUT of a child process and $stream2 is the STDERR of the same child process
- $stream1 is one child process and $stream2 is another child process

Is there a possiblility in perl to monitor two or more streams at the same time?

So we loop as long as anything pops-up in any of the streams and we take whatever comes first either in $stream1 or $stream2.

Something like

while (my $line = <$stream1 or $stream2> ) {  
    #do something with the $line
}

??

ludwika
  • 73

1 Answers1

3

Sure there is - it's Perl, after all - just not with quite such an elegant syntax.

Monitoring several streams boils down to judicious use of the select syscall, and in Perl that means using the four-argument version of select, which wraps this syscall. Many people find this a bit too cumbersome and low-level, so of course there is a module which further wraps the pattern for your convenience.

Kilian Foth
  • 109,273