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 (37)
- batch file suppress prompt (10)
- supress cmd are you sure (3)
- suppress prompt in bat file delete (2)
- suppress prompts in batch files (1)
- automatically reply to run prompt from batch file (1)
- suppress errors in command prompt (1)
- suppress errors batch file (1)
- suppress dir file not found (1)
- Supress prompt -deletecontent (1)