| # Run @$argv in the background with stdout redirected to $out. |
| exec(@$argv) or die "cannot exec '$argv->[0]': $!" |
| # Wait for $pid to finish. |
| # Simplified from wait_or_whine() in run-command.c. |
| my $waiting = waitpid($pid, 0); |
| die "waitpid failed: $!"; |
| warn "died of signal $code"; |
| # Note: the real sendfile() cannot read from a terminal. |
| # It is unspecified by POSIX whether reads |
| # from a disconnected terminal will return |
| # EIO (as in AIX 4.x, IRIX, and Linux) or |
| # end-of-file. Either is fine. |
| copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!"; |
| die "usage: test-terminal program args"; |
| my $master = new IO::Pty; |
| my $slave = $master->slave; |
| my $pid = start_child(\@ARGV, $slave); |
| xsendfile(\*STDOUT, $master); |
| exit(finish_child($pid)); |