7 # Run @$argv in the background with stdio redirected to $out and $err.
9 my ($argv, $out, $err) = @_;
11 if (not defined $pid) {
14 open STDOUT
, ">&", $out;
15 open STDERR
, ">&", $err;
17 exec(@
$argv) or die "cannot exec '$argv->[0]': $!"
22 # Wait for $pid to finish.
24 # Simplified from wait_or_whine() in run-command.c.
27 my $waiting = waitpid($pid, 0);
29 die "waitpid failed: $!";
32 warn "died of signal $code";
42 # Note: the real sendfile() cannot read from a terminal.
44 # It is unspecified by POSIX whether reads
45 # from a disconnected terminal will return
46 # EIO (as in AIX 4.x, IRIX, and Linux) or
47 # end-of-file. Either is fine.
48 copy
($in, $out, 4096) or $!{EIO
} or die "cannot copy from child: $!";
54 defined $pid or die "fork failed: $!";
57 xsendfile
(\
*STDERR
, $err);
61 xsendfile
(\
*STDOUT
, $out);
62 finish_child
($pid) == 0
67 die "usage: test-terminal program args";
69 my $master_out = new IO
::Pty
;
70 my $master_err = new IO
::Pty
;
71 my $pid = start_child
(\
@ARGV, $master_out->slave, $master_err->slave);
72 close $master_out->slave;
73 close $master_err->slave;
74 copy_stdio
($master_out, $master_err);
75 exit(finish_child
($pid));