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 (34)
- batch file suppress prompt (10)
- del suppress prompt (9)
- suppress prompt batch file (8)
- windows batch files commands reference (3)
- batch file suppress error (3)
- suppress file not found dir (3)
- batch suppress prompt (2)
- delete file cmd silent (2)
- batch file silent delete (2)