home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / NPIPE.ZIP / SAMPLE.ARC / HELLO.DOC < prev    next >
Text File  |  1991-06-11  |  2KB  |  46 lines

  1. HELLO.DOC 
  2. 10-June-1991
  3. Theo Jenetopulos
  4.  
  5.  
  6. This is sample code to demonstrate how to redirect 'stderr' in a 
  7. Presentation Manager program.
  8.  
  9. The sample program does the redirection and prints to standard out and 
  10. standard error every time a WM_PAINT message occurs.
  11.  
  12. Redirecting 'stderr' is useful to do since 'C' library function errors
  13. are printed there.  If you have ever had your PM program disappear from the
  14. screen with no trace, changes are you encountered just that sort of error.
  15. (An easy way to make this happen is to cause a divide by zero.)
  16.  
  17. My program NPIPE.EXE allows you pipe the standard out from any program to 
  18. a named pipe which can be viewed in another OS/2 window by running the NPIPE
  19. in read mode.  In order for stderr output to be viewed there you need to 
  20. redirect the output in your program.
  21.  
  22. This is takes just a few lines of code to do...
  23.  
  24.  
  25.     HFILE    hStdError;        /* Standard Error */
  26.     HFILE    hStdOut;        /* Standard Out */
  27.  
  28.     hStdOut = fileno(stdout);    /* Get the handle for stdout */
  29.     hStdError = fileno(stderr);    /* Get the handle for stderr */
  30.  
  31.     DosClose(hStdError);        /* Close the current stderr */
  32.     DosDupHandle(hStdOut, &hStdError);    /* Redirect stderr to stdout */
  33.  
  34.  
  35.  
  36.  
  37. My sample program HELLO.C also cleans up after itself by saving the original
  38. handle for standard error and putting it back before the program exits.
  39. As far as I can tell this is not really necessary unless you want to spawn
  40. processes that have the proper standard error.
  41.  
  42.  
  43.  
  44.  
  45. (Thanks to Joe Schmitt for comming up with this redirection code.)
  46.