Why DOS output of DEL commands to a file won't display error messages?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vhogan
    New Member
    • Jan 2011
    • 2

    Why DOS output of DEL commands to a file won't display error messages?

    Hi. Yes DOS still lives.... I am directing multiple delete (DEL) commands to an output file e.g.
    del /F /Q D:\Oracle\CoreM id\Apache\Apach e\logs\*.* >vh.txt
    del /F /Q D:\Oracle\Core\ Apache\Apache\l ogs\*.* >>vh.txt
    del /F /Q D:\Oracle\CoreM id\opmn\logs\*. * >>vh.txt
    del /F /Q D:\Oracle\CoreM id\webcache\log s\*.* >>vh.txt
    del /F /Q D:\Oracle\CoreI nfra\opmn\logs\ *.* >>vh.txt

    I am appending the output in each case except line 1 - that part is ok.
    However when there is an error message it doesnt appear in the output file. For example if I run this command (del /F /Q D:\Oracle\CoreM id\opmn\logs\*. *) at Dos prompt I get:
    D:\Oracle\CoreM id\opmn\logs\HT TP_Server~1
    The process cannot access the file because it is being used by another process.
    D:\Oracle\CoreM id\opmn\logs\ip m.log
    The process cannot access the file because it is being used by another process.
    D:\Oracle\CoreM id\opmn\logs\OC 4J~home~default _island~1
    The process cannot access the file because it is being used by another process.

    However if I run it with output to file vh.txt i get:
    D:\Oracle\CoreM id\opmn\logs\HT TP_Server~1
    D:\Oracle\CoreM id\opmn\logs\ip m.log
    D:\Oracle\CoreM id\opmn\logs\OC 4J~home~default _island~1

    As you can see there are no error message in the output results that are written to file, but they are displayed if output is to screen.
    How can I capture the error messages in the output file???
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    The error messages are pipe to stderr however >vh.txt redirects stdout to vh.txt so the file only contains messages sent to stdout and messages sent to stderr are not present.

    You need to redirect messages to stderr to stdout and messages to stdout to your file. You can redirect messages to stderr to stdout using the syntax "2>&1" (pipe stream 2 to stream 1) so you whole command should be

    del /F /Q D:\Oracle\CoreM id\Apache\Apach e\logs\*.* >vh.txt 2>&1

    Comment

    • vhogan
      New Member
      • Jan 2011
      • 2

      #3
      Thanks Banfa, that was very helpful and what's more it worked first time!!!

      Thanks again.

      V

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        There are three standard files associated with DOS (from Unix) programs :-
        stdin
        stout
        stderr

        Correctly written programs or filters will always send their error messages to stderr to avoid any potential of corrupting stdout (which may, of course, be used by another process as its stdin and is often parsed in a particular way - that doesn't include handling error text)

        I must admit though (I haven't used any of it for a while mind) that I wasn't aware that stout could be reassigned from a DOS command line (although I have a vague recollection that I've always known it could be done in Unix). Nice one Banfa. I learned something today.

        Comment

        Working...