6 use POSIX ":sys_wait_h";
11 my $out = shift @ARGV;
14 open my $fout, ">>", $out or die "Can't write to $out: $!" if $out;
16 my $select = IO::Select->new();
19 my $interactive = -t STDOUT;
26 $kid = waitpid( -1, WNOHANG );
33 $SIG{CHLD} = \&sigchld;
35 $pid = open3( "<&STDIN", \*child_out, \*child_err, @ARGV );
42 fcntl ( $h, F_GETFL, $flags )
43 or die "Couldn't get flags for HANDLE : $!\n";
45 fcntl ( $h, F_SETFL, $flags )
46 or die "Couldn't set flags for HANDLE: $!\n";
51 sethandle( \*child_out );
52 sethandle( \*child_err );
55 foreach my $h ( $select->can_read() ) {
57 print $fout $_ if $fout;
58 if ( $interactive && $h == \*child_err ) {
59 print "\033[31m$_\033[0m";