2

On Unix shells, such as sh or bash, there is a -e flag that causes it to stop executing a script as soon as a command encounters an error.

Is there any equivalent for Windows CMD.EXE? If not, why not -- it seems obviously useful?

I have done a lot of googling, but can't find any solution. Yet, it seems like such a major problem that I'd expect Microsoft to have added a solution at some point - they have not been afraid to enhance other aspects of CMD.

6
  • I think it depends on the type of error. There are some errors that are just unacceptable and cmd aborts immediately. Other types, not so much. And pretty much anytime, you can put in a line that says "if %errorlevel% neq 0 exit" But there is no -e that I'm aware of. – Larryc Sep 16 '19 at 0:50
  • SomeCommand.exe || EXIT /B 1 – Sirex Sep 16 '19 at 1:21
  • it's possible in powershell How to stop a PowerShell script on the first error?, but in cmd you'll have to handle that yourself. You should use powershell for new code anyway – phuclv Sep 16 '19 at 5:01
  • Hm, you're right phuclv. – O'Rooney Sep 16 '19 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.