Mail Archives: djgpp-workers/1999/05/10/02:40:51
On Sun, 9 May 1999, Richard Dawe wrote:
> I guess this question boils down to: Is it possible to capture stdout,
> stderr, etc. and still have them printed to the display?
Any DJGPP program can easily capture its own output using the FSEXT
features. That's exactly what the ported `ls' does to implement
colored output: it captures stdout and redirects it to direct screen
writes using conio functions.
So Bash could easily capture and stash away its own output (except
that in Bash's case you will need some more trickery to catch handles
other than 1 and 2 that were connected to the screen).
The *real* problem is to catch output of other programs. You need
either (1) install a real-mode callback that filters Int 21h
functions, or (2) hook Int 31h in protected mode and monitor the
__dpmi_int calls to Int 21h, or (3) implement some low-level machinery
that will allow the parent and child to jump between one and the other
using some ljmp/lcall trickery and hidden parameters a-la !proxy.
The first solution is a royal pain because RMCBs impose a lot of
restrictions: you need to lock all memory touched while in the
callback, so you cannot call library functions (or need to lock
everything and lose virtual memory); and the RMCB stack is too small
for anything serious.
(During one of the related discussions another possibility came up:
use the debugger support in libdbg.a to load and run another program
as debuggers do. This makes some problems, like jumping between the
two programs, easier, but raises other problems.)
The two other solutions above are, of course, DJGPP-specific, but
otherwise don't have any major drawbacks (at least no KNOWN drawbacks,
that is ;-). Solution (3) is probably the best one, since hooking Int
31h will make things slow. But they both require some low-level
infrastructure to be written.
Note that if we implement something like this, we would have done 90%
of work required to allow simulated multi-processing a-la fork/execc
(e.g., by switching context on a __dpmi_int call), signal delivery
between processes (see library function `kill'), and a few other
lucrative features. There's much more here than just capturing output.
So: any takers?
- Raw text -