delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/17/10:52:41

Date: Wed, 17 Jun 1998 16:51:29 +0200 (CEST)
Message-Id: <199806171451.QAA08532@login-2.eunet.no>
From: "Gisle Vanem" <giva AT bgnett DOT no>
To: blp01 AT uow DOT edu DOT au
Cc: djgpp AT delorie DOT com
Subject: Re: Redirecting output
MIME-Version: 1.0

On Wed, 17 Jun 1998, Brett Porter wrote:

> 	I'm working on a text based project here which uses text windows on
> occasion and shells to other programs.
>       I was wondering if it is possible to redirect the output of this program
> into the window. The window will probably use the "conio.h" functions to
> define it, but called programs will ignore this using stdout. Even if the
> programs use cprintf, it won't know the calling programs settings will it?

If the sub-program writes to stdout (or stderr), then the parent program
can trap all text by installing a handler for real-mode interrupt 29h.
Allocate a real-mode callback (rmcb) in your program. The RMCB gets called
for each character written, so it might be a bit slow (switching back and
forth between real/prot mode). 

If the sub-program is written in Borland and is using conio functions
the RMCB might (?) work provided `directvideo' is false.

AFAIK, no code needs to be locked, but beware not to use more that 2k(?)
of stack in the callback.

Here is a snippet of something I once made to accomplish this;

-------------------------- cut here ------------------------------

#include <stdlib.h>
#include <conio.h>
#include <dpmi.h>
#include <go32.h>

static _go32_dpmi_seginfo rm_cb, int29_old;
static __dpmi_regs        rm_reg;

static void int29_isr (void)
{
  putch (rm_reg.h.al);  /* print to your conio window etc. */
}

void int29_exit (void)
{
  if (rm_cb.pm_offset)
  {
    _go32_dpmi_set_real_mode_interrupt_vector (0x29,&int29_old);
    _go32_dpmi_free_real_mode_callback (&rm_cb);
    rm_cb.pm_offset = 0;
  }
}

void int29_init (void)
{
  _go32_dpmi_get_real_mode_interrupt_vector (0x29,&int29_old);
  rm_cb.pm_offset = (unsigned long) &int29_isr;
  if (_go32_dpmi_allocate_real_mode_callback_iret(&rm_cb,&rm_reg) ||
      _go32_dpmi_lock_data(&rm_reg,sizeof(rm_reg)))
    return;

  _go32_dpmi_set_real_mode_interrupt_vector (0x29,&rm_cb);
  atexit (int29_exit);
}

-------------------------- cut here ------------------------------

Gisle V.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019