home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / info / ntkb / ntkb.exe / Q110 / 9 / 30.TXT < prev    next >
Encoding:
Text File  |  1994-02-03  |  2.8 KB  |  74 lines

  1. DOCUMENT:Q110930  02-FEB-1994  [W_NT]
  2. TITLE   :Redirecting Error Messages from Command Prompt: STDERR/STDOUT
  3. PRODUCT :Windows NT
  4. PROD/VER:3.10
  5. OPER/SYS:WINDOWS
  6. KEYWORDS:
  7.  
  8. ----------------------------------------------------------------------
  9. The information in this article applies to:
  10.  
  11.  - Microsoft Windows NT operating system version 3.1
  12.  - Microsoft Windows NT Advanced Server version 3.1
  13. ----------------------------------------------------------------------
  14.  
  15. When redirecting output from an application using the ">" symbol, error
  16. messages still print to the screen. This is because error messages are
  17. often sent to the Standard Error stream instead of the Standard Out stream.
  18.  
  19. Output from a console (Command Prompt) application or command is often sent
  20. to two separate streams. The regular output is sent to Standard Out
  21. (STDOUT) and the error messages are sent to Standard Error (STDERR). When
  22. you redirect console output using the ">" symbol, you are only redirecting
  23. STDOUT. In order to redirect STDERR you have to specify "2>" for the
  24. redirection symbol. This selects the second output stream which is STDERR.
  25.  
  26. EXAMPLE
  27. =======
  28.  
  29. The command "dir file.xxx" (where file.xxx does not exist) will display the
  30. following output:
  31.  
  32.    Volume in drive F is Candy Cane
  33.    Volume Serial Number is 34EC-0876
  34.  
  35.    File Not Found
  36.  
  37. If you redirect the output to the NUL device using "dir file.xxx > nul",
  38. you will still see the error message:
  39.  
  40.    File Not Found
  41.  
  42. To redirect the error message to NUL, use the following command:
  43.  
  44.    dir file.xxx 2> nul
  45.  
  46. Or, you can redirect the output to one place, and the errors to another.
  47.  
  48.    dir file.xxx > output.msg 2> output.err
  49.  
  50. You can print the errors and standard output to a single file by using the
  51. "&1" command to redirect the output for STDERR to STDOUT and then sending
  52. the output from STDOUT to a file:
  53.  
  54.    dir file.xxx 1> output.msg 2>&1
  55.  
  56. Additional reference words: 3.10 pipe UNIX stdin re-directed
  57. KBCategory:
  58. KBSubCategory: howto
  59.  
  60. =============================================================================
  61.  
  62. THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS
  63. PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.  MICROSOFT DISCLAIMS
  64. ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES
  65. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO
  66. EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR
  67. ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL,
  68. CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF
  69. MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE
  70. POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO NOT ALLOW THE EXCLUSION
  71. OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES
  72. SO THE FOREGOING LIMITATION MAY NOT APPLY.
  73.  
  74. Copyright Microsoft Corporation 1994.