home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
NPIPE.ZIP
/
SAMPLE.ARC
/
HELLO.DOC
< prev
next >
Wrap
Text File
|
1991-06-11
|
2KB
|
46 lines
HELLO.DOC
10-June-1991
Theo Jenetopulos
This is sample code to demonstrate how to redirect 'stderr' in a
Presentation Manager program.
The sample program does the redirection and prints to standard out and
standard error every time a WM_PAINT message occurs.
Redirecting 'stderr' is useful to do since 'C' library function errors
are printed there. If you have ever had your PM program disappear from the
screen with no trace, changes are you encountered just that sort of error.
(An easy way to make this happen is to cause a divide by zero.)
My program NPIPE.EXE allows you pipe the standard out from any program to
a named pipe which can be viewed in another OS/2 window by running the NPIPE
in read mode. In order for stderr output to be viewed there you need to
redirect the output in your program.
This is takes just a few lines of code to do...
HFILE hStdError; /* Standard Error */
HFILE hStdOut; /* Standard Out */
hStdOut = fileno(stdout); /* Get the handle for stdout */
hStdError = fileno(stderr); /* Get the handle for stderr */
DosClose(hStdError); /* Close the current stderr */
DosDupHandle(hStdOut, &hStdError); /* Redirect stderr to stdout */
My sample program HELLO.C also cleans up after itself by saving the original
handle for standard error and putting it back before the program exits.
As far as I can tell this is not really necessary unless you want to spawn
processes that have the proper standard error.
(Thanks to Joe Schmitt for comming up with this redirection code.)