]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - teeboth
do not purge if stash list not empty
[packages/rpm-build-tools.git] / teeboth
CommitLineData
d8c44621
PI
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use Fcntl;
6use POSIX ":sys_wait_h";
7use IPC::Open3;
8use IO::Handle;
9use IO::Select;
10
11my $out = shift @ARGV;
12die unless @ARGV;
13
363d2ccc 14open my $fout, ">>", $out or die "Can't write to $out: $!" if $out;
d8c44621
PI
15
16my $select = IO::Select->new();
17my $alive = 1;
18my $pid;
19
20my $code;
21sub sigchld
22{
23 my $kid;
24 do {
25 $kid = waitpid( -1, WNOHANG );
26 if ( $kid == $pid ) {
27 $code = $? >> 8;
28 $alive = 0
29 }
30 } while ( $kid > 0 );
31}
32$SIG{CHLD} = \&sigchld;
33
34$pid = open3( \*child_in, \*child_out, \*child_err, @ARGV );
35close child_in;
36
37sub sethandle
38{
39 my $h = shift;
40 my $flags = 0;
41
42 fcntl ( $h, F_GETFL, $flags )
43 or die "Couldn't get flags for HANDLE : $!\n";
44 $flags |= O_NONBLOCK;
45 fcntl ( $h, F_SETFL, $flags )
46 or die "Couldn't set flags for HANDLE: $!\n";
9db5cbe8 47
d8c44621
PI
48 $select->add( $h );
49}
50
51sethandle( \*child_out );
52sethandle( \*child_err );
53
54while ( $alive ) {
55 foreach my $h ( $select->can_read() ) {
56 sysread $h, $_, 1024;
9db5cbe8 57 print $fout $_ if $fout;
d8c44621
PI
58 if ( $h == \*child_err ) {
59 print "\033[31m$_\033[0m";
60 } else {
61 print $_;
62 }
63 STDOUT->flush();
64 }
65}
66
67exit $code;
This page took 0.035048 seconds and 4 git commands to generate.