Windows batch equivalent of bash's set -e

Is there a Windows batch equivalent to bash's set -e, which causes the shell to exit immediately if a command fails with nonzero exit status (except in places where it's expected like in an if statement)? I gets tiring to put if errorlevel 1 exit 1 after every single line.


Solution 1:

To specify more than one command on the command prompt line by using the ampersand character as a command separator:

dir & pause

For conditional execution of your command using two other command separators. If you separate two command using a double ampersand (&&), then the second command will be executed only if the first command runs successfully:

dir && pause

If you use a double bar (||) as command separator, then the second command will only be executed if the first command fails:

dir Nonsensual-mix || pause

Therefore you could use next:

your_command || exit 1