8
# Run @$argv in the background with stdio redirected to $out and $err.
10
my ($argv, $out, $err) = @_;
12
if (not defined $pid) {
15
open STDOUT, ">&", $out;
16
open STDERR, ">&", $err;
18
exec(@$argv) or die "cannot exec '$argv->[0]': $!"
23
# Wait for $pid to finish.
25
# Simplified from wait_or_whine() in run-command.c.
28
my $waiting = waitpid($pid, 0);
30
die "waitpid failed: $!";
33
warn "died of signal $code";
43
# Note: the real sendfile() cannot read from a terminal.
45
# It is unspecified by POSIX whether reads
46
# from a disconnected terminal will return
47
# EIO (as in AIX 4.x, IRIX, and Linux) or
48
# end-of-file. Either is fine.
49
copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!";
55
defined $pid or die "fork failed: $!";
58
xsendfile(\*STDERR, $err);
62
xsendfile(\*STDOUT, $out);
63
finish_child($pid) == 0
68
die "usage: test-terminal program args";
71
my $parent_out = new IO::Pty;
72
my $parent_err = new IO::Pty;
73
$parent_out->set_raw();
74
$parent_err->set_raw();
75
$parent_out->slave->set_raw();
76
$parent_err->slave->set_raw();
77
my $pid = start_child(\@ARGV, $parent_out->slave, $parent_err->slave);
78
close $parent_out->slave;
79
close $parent_err->slave;
80
copy_stdio($parent_out, $parent_err);
81
my $ret = finish_child($pid);