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";
70 my $master_out = new IO::Pty;
71 my $master_err = new IO::Pty;
72 $master_out->set_raw();
73 $master_err->set_raw();
74 $master_out->slave->set_raw();
75 $master_err->slave->set_raw();
76 my $pid = start_child(\@ARGV, $master_out->slave, $master_err->slave);
77 close $master_out->slave;
78 close $master_err->slave;
79 copy_stdio($master_out, $master_err);
80 exit(finish_child($pid));