0

I am facing the following issue and would really appreciate some help since I am a newcomer to windows systems:

I am writing a script which launches an executable at some point. This executable is likely to fail and I would like my batch file to stop running in this case. My researches led me to the following link: Does Windows batch support exception handling? (first answer).

The problem with this answer is that it seems (unless I am misled) to work only when the called target's source code is reachable. Anyway the solution seems really complicated for what I would like to do. Is there a more straightforward way to detect a failure (being able to capture the error message or to use the errorcode would be more than enough) ? You may have a look at the enclosed screenshot for a better understanding of the issue.

Thank you for your help, hope this will be useful to more than one, regards

Appendix:

This first image shows the error message I would like to capture:
This first image shows the error message I would like to capture

This one shows the part of the script where I call the executable:
This one shows the part of the script where I call the executable

On the second image, the findstr instruction is used to look for a particular sentence in a logs file, if the sentence is found then we can assume the execution has been successful, otherwise we cannot conclude. This is a rather perfunctory solution...

aschipfl
  • 33,626
  • 12
  • 54
  • 99
J. Valjean
  • 35
  • 7
  • we don't know. Does your executable return errorcodes? (Btw: proper syntax `findstr /c:"the searched string"` (note the colon (no space!)) – Stephan May 14 '18 at 12:39
  • (another "btw": i guess, `ccomprehensive` is a typo) – Stephan May 14 '18 at 12:41
  • @Stephan : I tried doing an if errorlevel1 just after the call to my executable and it did nothing so I assume it does not handle errocodes at all. Thank you for the correction, I substituted my findstr instruction with yours and it seems like the errorcode level is ignored, so there is definitely something fishy there. Indeed 'ccomprehensive' is a typo but it is a typo which actually displays as it is in the logs so this is why I have to keep it ! – J. Valjean May 14 '18 at 13:13
  • you process the errorlevel of `findstr`, which is reliable; so it should work fine. Check your string (case sensitive; and is there really no punktuation between `[S/s]uccessfully` and `Please`?). – Stephan May 14 '18 at 13:25
  • @Stephan It finally worked, the error was that I forgot an '&' between two instructions on the same line. But I would like to find another means to do the thing, because eventually the log files can change and/or there could be several sentences able to acknowledge a successful run and ideally I won't have to come back to the batch to update it each time a new feature is added... – J. Valjean May 14 '18 at 13:52
  • see `findstr /?`, `/g` switch. (keep the strings in a text file instead of bothering with the batchfile itself) - not ideal, but when your application don't return proper errorlevels, that's at least an option. – Stephan May 14 '18 at 14:02
  • @Stephan Yes sounds like a good option, thank you ! – J. Valjean May 14 '18 at 15:31

0 Answers0