--- ./os2/OS2/Process/Process.pm-pre	Thu Sep 11 14:48:24 2003
+++ ./os2/OS2/Process/Process.pm	Fri Sep 19 19:54:24 2003
@@ -573,6 +573,64 @@ sub kbdhStatus_set {
   _kbdStatus_set($o,$h);
 }
 
+# Large buffer works at least for read from pipes
+sub __term_mirror_screen {   # Read from fd=$in and write to the console
+  my $in = shift;
+  open IN, "<&=$in" or die "open <&=$in: $!";
+  # Attempt to redirect to STDERR/OUT is not very useful, but try this anyway...
+  open OUT, '>', '/dev/con' or open OUT, '>&STDERR' or open OUT, '>&STDOUT'
+        or warn "Cannot reopen STDOUT to /dev/con or STDERR/STDOUT";
+  select OUT; $| = 1; local $SIG{TERM} = sub { die "screenwriter exits...\n"};
+  eval { print while sysread IN, $_, 1<<16; }
+}
+
+sub __term_mirror {   # Read from fd=$in and pass through; same for $out
+  my $pid;
+  local $SIG{TERM} = sub { die "keyreader exits...\n" };
+  my ($in, $out) = (shift, shift);
+  my %in = @_;
+  Title_set $in{title}			if exists $in{title};
+  &scrsize_set(split /,/, $in{scrsize})	if exists $in{scrsize};
+
+  $pid = system 1, $^X, '-MOS2::Process',
+	 '-we', 'OS2::Process::__term_mirror_screen shift', $in;
+  $pid > 0 or die "Cannot start a grandkid";
+
+  open STDIN, '</dev/con' or warn "reopen stdin: $!";
+  open OUT, ">&=$out" or die "Cannot open &=$out for writing: $!";
+  select OUT;    $| = 1;  binmode OUT;	# need binmode since sysread() is bin
+  $SIG{PIPE} = sub { die "writing to a closed pipe" };
+  # Turn Nodelay on kbd.  Pipe is automatically nodelay...
+  if ($in{read_by_key}) {
+    if (eval {require Term::ReadKey; 1}) {
+      Term::ReadKey::ReadMode(4);
+    } else { warn }
+  }
+  print while sysread STDIN, $_, 1<<($flag ? 16 : 0);
+}
+
+sub io_term {	# arguments: hash with keys read_by_key/title/scrsize
+  local $^F = 40;     # XXXX Fixme!
+  local $\  = '';
+  my ($in1, $out1, $in2, $out2);
+
+  pipe $in1, $out1 or return;
+  pipe $in2, $out2 or do { close($in1), close($out1), return };
+
+  # system P_SESSION will fail if there is another process
+  # in the same session with a "dependent" asynchronous child session.
+  my @i = map +('-I', $_), @INC;	# Propagate @INC
+  my $kpid = system 4, $^X, @i, '-we', <<'EOS', fileno $in1, fileno $out2, @_;
+     END {sleep($sleep || 5)}
+     use OS2::Process; $sleep = 1;
+     OS2::Process::__term_mirror(@ARGV);
+EOS
+  close $in1 or warn;
+  close $out2 or warn;
+  warn "system P_SESSION, $^X: $!, $^E" and do { close($in2), close($out1), return }
+    unless $kpid > 0;
+  return ($in2, $out1, $kpid);
+}
 
 # Autoload methods go after __END__, and are processed by the autosplit program.
 
