The title pretty much sums it up, but I'll elaborate on my question. Out of curiosity I've been putting commands in a block (usually with one command that won't work) and seeing if I can suppress the error messages and output a custom one. I tried two methods, the first one failed but the second worked.
1
@echo off
(
echo Blah
ehco Blah & rem Intentional mistake
echo Blah
) 2>nul||echo One of the commands failed.
pause>nul
Output:
Blah
Blah
2
@echo off
call :block 2>nul||echo One of the commands failed.
pause>nul
exit
:block
(
echo Blah
ehco Blah & rem Intentional mistake
echo Blah
)
goto :eof
Output:
Blah
Blah
One of the commands failed.
So, I've got the the second part of my question answered, now I just need to know how to (if one of the commands failed) suppress any output except the custom error message. So, the desired output would be One of the commands failed.
. How would I go about doing this?
NOTE:
I've heard that you can do something like echo Blah 2>&1nul
or something like that, and I guess that would be the way to go. But I'm also guessing that would make it suppress the output every time the command is run, not just when there's an error message.
Also, in your answer, if you could do a brief explanation of why the first script failed, that would be dandy.