Let's say I already have a folder created on the next path file: "C:\users\charqus\desktop\MyFolder"
, and I run the next command on CMD:
mkdir "C:\users\charqus\desktop\MyFolder"
I get a message like this: "A subdirectory or file C:\users\charqus\desktop\MyFolder already exists".
Therefore, is there any command in the commandline to get rid of this returned messages? I tried echo off but this is not what I looking for.
To suppress error output in bash , append 2>/dev/null to the end of your command. This redirects filehandle 2 (STDERR) to /dev/null .
You can also use the shortcut key Alt + F4 to close a Command Prompt window.
When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.
Redirect the output to nul
mkdir "C:\users\charqus\desktop\MyFolder" > nul
Depending on the command, you may also need to redirect errors too:
mkdir "C:\users\charqus\desktop\MyFolder" > nul 2> nul
Microsoft describes the options here, which is useful reading.
A previous answer shows how to squelch all the output from the command. This removes the helpful error text that is displayed if the command fails. A better way is shown in the following example:
C:\test>dir Volume in drive C has no label. Volume Serial Number is 4E99-B781 Directory of C:\test 20/08/2015 20:18 <DIR> . 20/08/2015 20:18 <DIR> .. 0 File(s) 0 bytes 2 Dir(s) 214,655,188,992 bytes free C:\test>dir new_dir >nul 2>nul || mkdir new_dir >nul 2>nul || mkdir new_dir C:\test>dir new_dir >nul 2>nul || mkdir new_dir >nul 2>nul || mkdir new_dir
As is demonstrated above this command successfully suppress the original warning. However, if the directory can not be created, as in the following example:
C:\test>icacls c:\test /deny "Authenticated Users":(GA) processed file: c:\test Successfully processed 1 files; Failed processing 0 files C:\test>dir new_dir2 >nul 2>nul || mkdir new_dir2 >nul 2>nul || mkdir new_dir2 Access is denied.
Then as can be seen, an error message is displayed describing the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With