How to specify /D in FOR command?

Viewed 383

The Windows command line interpreter features a FOR command, which is able to parse the output of a given command and execute the loop for each line of the output, e.g.:

FOR /F %%i IN ('DIR .') DO echo %i # Outputs each file name

The command (DIR .) is executed in a child command line via cmd /C <command> <command-arguments>, however, the /D parameter is not specified ... this leads to weird behavior if the user has a AutoRun command with output (e.g. echo, or cls).

Is there a way to force FOR to execute the command via cmd /C /D <command> <command-arguments>?

3 Answers
Related