I'm writing a simple .bat script and I want it to open it by double click from Windows Explorer. If opened from Windows Explorer, console window automatically closes after script is finished.
The problem is that errors may occur from commands that I invoke in a script. In this case these comands print out error messages and return exit status 1. But user don't know about it because Window closes too fast to notice if some error messages popped out (and definitely too fast to read them ;) ).
So is there any way to prevent console window from closing if some command in script failed (so that user can read error message) and still having it automatically closed if everything worked fine? If the second part is not possible, it's okay to just prevent console window to close automatically in both cases (either failure or success).
It would be much easier to go with the latter. To keep the console window open put this at the end of your script:
That will pause the window from closing. Then you can handle any errors you want to display and presumably
echo them to the user before the
echo No errors or Errors found!
Hope this helps!