Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to dir a bunch of files with dos command: dir

My dir.bat file:

dir E:\documentos\57\Asiento\01\"Asiento 3 Modificacion de Estatuto.doc"
dir E:\documentos\134\Asiento\01\"File Does Not Exist.doc"
dir E:\documentos\55\Asiento\01\"Asiento 5 Padron de Afiliados Segunda Entrega.doc"

The second one doesn't exist.

Then, when running my bat:

C:\myuser>E:\dir.bat > output.log

I open output.log and don't find any message about the file that was not found.

Output.log :

E:\documentos>dir E:\documentos\57\Asiento\01\"Asiento 3 Modificacion de Estatuto.doc" 
 Volume in drive E is New Volume
 Volume Serial Number is 0027-F7F6

 Directory of E:\documentos\57\Asiento\01

20/12/2005  06:41 p.m.            40,960 Asiento 3 Modificacion de Estatuto.doc
               1 File(s)         40,960 bytes
               0 Dir(s)  17,053,155,328 bytes free

E:\documentos>dir E:\documentos\134\Asiento\01\"File Does Not Exist.doc" 
 Volume in drive E is New Volume
 Volume Serial Number is 0027-F7F6

 Directory of E:\documentos\134\Asiento\01


E:\documentos>dir E:\documentos\55\Asiento\01\"Asiento 5 Padron de Afiliados Segunda Entrega.doc" 
 Volume in drive E is New Volume
 Volume Serial Number is 0027-F7F6

 Directory of E:\documentos\55\Asiento\01

08/08/2007  08:33 a.m.            40,960 Asiento 5 Padron de Afiliados Segunda Entrega.doc
               1 File(s)         40,960 bytes
               0 Dir(s)  17,053,151,232 bytes free

Is there any way that output.log shows "File Not Found" message?

share|improve this question
add comment

1 Answer

I found my own answer:

C:\myuser>E:\dir.bat > output.log 2>&1

This will redirect the "File Not Found" message to output.log and not showing on CMD.

share|improve this answer
    
The main reason here being that a "File not found" message from the dir command is sent to STDERR, while a simple redirect using > only redirects STDOUT - see en.wikipedia.org/wiki/Standard_streams for details. Using the 2>&1 notation redirects STRERR (2) into STDOUT which is finally redirected into your log file. –  the-wabbit Sep 24 '12 at 22:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.