I have a post-build event that runs some commands for a c# project. The last command would sometimes cause the ERRORLEVEL value not equals to zero and then the build fails.
I want to append an extra line of command to always set the ERRORLEVEL value to zero. What is the most convenient way to do that?
If this is a snippet like "Post-build Event" etc., then you'll be fine appending:
at the end of the last command.
Alternatively
is very clean and non-idiomatic -- a reader who knows Windows shell will know what's going on, and what was your intent.
However, if you're in a batch script, you may want to use subrotines, which are a lightweight equivalent of the "child batch script" from akf's answer.
Have a subroutine:
and then just
wherever you need it.
Here's a complete example:
Which outputs:
As you see - just calling and returning via goto:eof is not enough.
I found that "exit 0" looks like a good way to deal with this problem.
Usage Example:
if the UnderDevService service is not started.
I'm using this:
ping localhost -n 1 >null
I personally use this:
cd .
Works even in unix shell.
But, this one might be a bit faster:
type nul>nul
Because
Process Monitor
showsQueryDirectory
calls oncd .
PS:
cd .
has another nice side effect in the unix shell. It does restore recreated working directory in the terminal if it has been opened before the erase.Seems to do the trick:
Not everything works, and it is not clear why. For example, the following do not:
I use
VERIFY
orVERIFY > nul