Reply
Wed 3 Dec, 2003 02:47 pm
I've seen this, used this, but haven't found any explanation for this.
Why do we need the >nul in batch scripting, IE:
dir|find "Volume in drive %DRIVE% is MI_">nul
And what does this snippet of code accomplish?
it prevents any output message.
It's just like > /dev/null in other languages. Surpresses an error message etc.
thx, so feasibly I could run it at the end of every command instead of using the @Echo off at the beginning if I desired greater flexibility and wasn't worried about size? or am I a little eensy-weensy bit off?
@echo off supresses the script from being displayed. it still displays any output generated by the script. >nul displays the script but supresses any output generated.
music2myear, here's an example of ye110man's good explanation. . . say the following command was being processed in a batch file:
Code:copy a:\*.* b:\*.*
@echo off would prevent "
C:\>copy a:\*.* b:\*.*" from being shown, while
>nul would suppress its output (which would be either "
X files copied successfully" or an error message).
Edit: typo fixed
music2myear wrote:thx, so feasibly I could run it at the end of every command instead of using the @Echo off at the beginning if I desired greater flexibility and wasn't worried about size?
If you wanted greater control over the ECHO state, what you need isn't "
>nul" but "
@".
Regardless of the ECHO state, a batch file line that begins with the [@] character will not be displayed.