Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →
...
for /F %%F in ('dir /B %* 2> nul') do (
...

What I'm attempting to do here is discard the err output of the command (and loop over the stdout output). However, it complains:

2> was unexpected at this time.

Is this some way to achieve this?

share|improve this question
up vote 19 down vote accepted

in this case you need to escape the > like this

for /F %%F in ('dir /B %* 2^> nul') do (
share|improve this answer
1  
Microsoft uses an intern to implement the command shell and we have to live with it for the rest of our lives... – bambams Jun 10 '15 at 17:14

I believe you need a delimiting space between the "2" and the ">". Without that delimiter my dir test output still displayed on the screen. Furthermore, I believe that by sending the output of the dir command to null will not provide any data back for the set to process.

share|improve this answer
2  
No. Changing 2> to 2 > would redirect STDOUT instead of STDERR, thus preventing the processing of the actual directory listing. As @RGuggisberg correctly pointed out, the redirection operator must be escaped in the nested command. – Ansgar Wiechers Jun 14 '13 at 17:22

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.