Solved What does the ^ do in this string: /b /a:-d /o:-d 2^NUL ?

February 5, 2012 at 15:19:12
Specs: Windows 7
What does the "^" do in this string: /b /a:-d /o:-d 2^>NUL ?

See More: What does the ^ do in this string: /b /a:-d /o:-d 2^NUL ?

Report •

February 5, 2012 at 15:22:49
Actually, the entire string, to be more fair is:

for /f "skip=10 delims=" %%a in ('dir *.tib /b /a:-d /o:-d 2^>NUL') do del /q "%%a"

And, a more complete question would be what does "2^" mean in that snippet?


Report •

February 6, 2012 at 06:12:13
✔ Best Answer
The ^ (caret) symbol is mandatory when you code a special character like the > redirector as part of a command used as FOR /F clause. 2>nul (2^>nul in the reported case) redirects stderr (2) to the nul device so erasing any error message to the screen (in the same way 1>nul suppresses any result line to the screen).

This to force the DIR command to run silently even if no files are found since the command output is piped to DEL by the FOR statement but the error messages are still directed to screen since stderr is different from stdout.

Anyway this has nothing to do with DOS that doesn't exist in Win 7 as NT kernel based. This is NT batch and what you believe to be the DOS command prompt actually is the NT system console.

Report •
Related Solutions

Ask Question