2011-07-13

How to use NUL Redirects in old fashoned style scripting - avoiding error responses on NUL redirects.

Geat Post on how to use the >NUL to suppress NUL 2 Error responses

This was a truth that i didn't know whats the string >nul 2>&1 means in batch scripting , even though i used it in many batch scripts :-) . Thanks to Dark for explaining it in the MSFN blog.

It redirects standard output, STDOUT, (1>nul), and standard error, STDERR, (2>nul), to nul.

STDOUT, channel 1, is the default therefore doesn't require the channel number stipulating, (>nul).

You can use
>nul 2>nul
which will redirect each channel to its own nul

Or you can use
>nul 2>&1
which redirects STDERR to the same nul as the STDOUT channel.


As for the (&), (&&)
& separates multiple commands on one command line.
&& causes the command following this symbol to run if the command preceding the symbol is successful.
Labels: Java, Suresh G

No comments:

Post a Comment

No Spam! Run Away, Run Away, Run Away!

Tweets