From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: Can I catch stderr output in my own code? Date: Thu, 10 Apr 1997 12:39:51 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 64 Message-ID: <334CD187.1CFB@LSTM.Ruhr-UNI-Bochum.De> References: <5iichm$418 AT info DOT service DOT rug DOT nl> NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Doug Eleveld wrote: > > Hello Everyone, > > I' know how to redirect stderr to a file and such, but what I'd like > to do is have my program process all the text that would normally > go to stderr (or stdout or from stdin) and display it in a window > in graphics mode. Do I have to take over a FILE* and then redirect to > that FILE*? Is there a more sensible way? Does anyone do this kind of > stuff with DJGPP? Two solutions come to my mind, one is to write code using the File System Extensions in DJGPP, close stderr and reopen it with a filename like "/dev/stderr_80x40" and your FSE catches it. The big advantage is, that you'll just have to handle characters, no sprintf() required. The advantage is you can catch stdout by the same way, so there is no difference between printf() and fprintf(stdout) int (*printfunc)(char *,..); #ifdef TEXTMODE printfunc = printf; #else printfunc = myprintf #endif /* ** This should go before the above */ int myprintf(char *fmt,...){ char buf[2048]; /* Beware: This can corrupt your stack when printing ** Lines longer than 2048 characters. Any idea how to ** catch that? */ va_args v=va_start(fmt); int retval; retval = vsprintf(buf,fmt,v); va_end(v); /* parse buf and display it the way you need it */ ... return retval; } int main(){ printfunc("This goes to %s\n", "wherever"); } THIS_IS_NOT_TESTED! (It probably won't even compile, but I hope you get the idea) -- Ciao Tom ************************************************************* * Thomas Demmer * * Lehrstuhl fuer Stroemungsmechanik * * Ruhr-Uni-Bochum * * Universitaetsstr. 150 * * D-44780 Bochum * * Tel: +49 234 700 6434 * * Fax: +49 234 709 4162 * * http://www.lstm.ruhr-uni-bochum.de/~demmer * *************************************************************