Commands such as deleting all files can complicate batch files because the system prompts for confirmation.
For example check the following command
del *.* replies with *.*, Are you sure (Y/N)?
Now if you don’t want to display prompt By using echo this will automatically reply for you
echo y | del *.*
del /q *.*
To supress the “File Not Found” error when trying to delete files from an empty directory, use this code instead:
if exist *.* echo y| del *.*
if exist *.* | del /q *.*
During the execution of your batch files, users can see your commands on the screen. Most of the time this is good for debugging purposes; however, often it’s better to run your batch file silently.
Any command that is followed by “> nul” will not be shown on the screen. The greater sign directs the output to null (nowhere).
For example, copy *.* *.bak will show you as it copies all the files in the directory and renames them with the bak extension.
copy *.* *.bak > nul will silently complete its work without placing anything on the screen.
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
Incoming search terms:
- suppress prompts in batch file (29)
- batch file suppress prompt (6)
- del suppress prompt (6)
- suppress confirmation prompt batch file (5)
- reg delete suppress error (4)
- suppress prompt batch file (4)
- dos suppress error (4)
- reg delete suppress output (3)
- delete files silently batch file (3)
- cmd suppress errors (3)