Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 264 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a "set -e" for a DOS batch script?

#1
In bash "set -e" at the beginning of the script instructs bash to fail the whole script on first failure of any command inside.

How do I do the same for a Windows batch script?
Reply

#2
Not directly but you can add the following to every line which has something to execute.

|| goto :error

And then define error, which stops the script.

:error
exit /b %errorlevel%
Reply

#3
Tuim's solution works, but it can be made even simpler.

The ERRORLEVEL is already set, so there is no need to GOTO a label that sets the ERRORLEVEL.

You can simply use

yourCommand || exit /b

Note that exit /b will only exit the current subroutine if you are in the middle of a CALL. Your script will have to exit each CALL, layer by layer, until it reaches the root of the script. That will happen automatically as long as you also put the test after each CALL statement

call :label || exit /b

It is possible to force a batch script to exit immediately from any CALL depth. See

[To see links please register here]

for more info. Be sure to read both answers. The accepted answer has a couple of potentially serious drawbacks.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through