1

I'm writing a .bat file that calls a .exe that processes a bunch of documents. I am writing it to test the .exe's performance. Currently, the .bat file runs a for loop to run the .exe on every file in the folder. Sometimes the .exe will run into errors and will not be able to finish running due to incompatibility between the document and the .exe (still working on perfecting the .exe). How can I tell my .bat file to mark the bad files as errors and continue processing the rest of the files?

Edit: I don't want to terminate the batch file; I'd like to terminate the .exe for that specific file, and then continue with the for loop.

  • 2
    possible duplicate of [How do I make a batch file terminate upon encountering an error?](http://stackoverflow.com/questions/734598/how-do-i-make-a-batch-file-terminate-upon-encountering-an-error) – icktoofay Aug 30 '15 at 03:26
  • Thanks for the link. Instead of terminating the whole batch file, do you think it would be possible to terminate the .exe for that specific file and then continue running on the others? – Jennifer Du Aug 30 '15 at 03:35
  • Absolutely. I was just providing that as a ‘duplicate’ since it provides information on how to figure out whether the previous command failed. All the examples there then exit the batch file if the command failed, but there’s no reason you couldn’t just do a `goto` to continue on to the next file. – icktoofay Aug 30 '15 at 03:36
  • In that case, would I point the `goto` to the beginning of the for loop? Would this guarantee that it processes the next file in line after the errorizing one? – Jennifer Du Aug 30 '15 at 03:40
  • I’m afraid I don’t know; I’m not *that* familiar with Batch and I try to avoid touching it if possible. – icktoofay Aug 30 '15 at 03:45
  • Haha, I see. Thanks for your help! – Jennifer Du Aug 30 '15 at 03:46
  • Mmmm... I think here is a confusion here. The .exe program should end _always_. That is, sometimes it ends correctly and sometimes it ends because an error caused by the file, but in any case the `for` loop pass to the next file, right? Are you saying that when there is an error, the .exe program does _NOT_ end? – Aacini Aug 30 '15 at 03:56
  • Hmm, okay. When I the .exe runs into errors, a box pops up that says ".exe has stopped working" and then I need to manually press "okay" to make the .exe end, at least when I did it in the cmd window. My goal is to make the .exe end by itself, even when it runs into errors. – Jennifer Du Aug 30 '15 at 04:18
  • Is the .exe a program of yours? If not, then there is no way to modify its behavior from the Batch file. However, test this from the command line running the .exe with a file with errors: `echo/| theProg.exe badFile.ext` This send an Enter to the .exe program. If it continue after the error, then it is the solution to your problem! – Aacini Aug 30 '15 at 04:29
  • IMHO the `"some.exe has stopped working"` popup is from _operating system_, not from the `some.exe` program. Please [edit] your question and add a relevant part of your code satisfying the [mcve] rules (otherwise, your question considered _off-topic_ and could tend to be closed). – JosefZ Aug 30 '15 at 07:56

0 Answers0