DISQUS

Tech-Recipes: Supress Responses From Commands In Batch Files | Batch file programming | Tech-Recipes

  • gmartin · 5 years ago
    This tip is good but it only goes so far. It will redirect STDOUT to null. Errors will still be displayed. As an example, run dir badfile.txt >nul and you will still see "File not found" displayed. That's because errors are written to STDERR

    To redirect STDERR to nul as well, try this:

    dir badfile.txt > nul 2&>1

    Of course you may want to see the errors. So a better tack to take could be to write to a log file

    dir badfile.txt >log.txt 2&>1

    \Greg
  • qmchenry · 5 years ago
    Greg,

    That is a fantastic piece of knowledge. I've been redirecting stderr that way in unix for many years, but I've never tried it in dos. I wouldn't have thought to try. I also didn't know there was an eqivalent to /dev/null in dos. Great stuff!

    Quinn
  • timlarsen · 5 years ago
    The actual syntax (at least on Win2K) is

    dir badfile.txt > null 2>&1

    Note the position of the ampersand.
  • Ghanny · 5 months ago
    For standard output also try "@echo off" at the start of the batch file. This will suppress echoing all the input commands.
  • X · 5 months ago
    <script language="javascript">window.alert('Nothing Special')</script>