Redirect output of command in for loop of batch sc

2019-02-04 10:23发布

...
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?

2条回答
放荡不羁爱自由
2楼-- · 2019-02-04 10:55

in this case you need to escape the > like this

for /F %%F in ('dir /B %* 2^> nul') do (
查看更多
可以哭但决不认输i
3楼-- · 2019-02-04 10:57

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.

查看更多
登录 后发表回答