I have a simple .bat script that runs an external console program and when it completes it outputs a couple lines of data.
Is there a way to look for a keyword in the console output after external program has completed.
For instance:
The external program completes, the .bat file looks for the keyword: success, and if it’s found it saves the console output conversely if the keyword is: failed then the .bat program exits.
Usually checks for success are done by directly checking the external process’s return code with the
IF ERRORLEVELconstruct:Of course this is dependent on the external program, so you might simply not be able to use it. In that case you can redirecting the output of the external program and using
findto look for it;finduses a nonzero (don’t remember exactly) return code to signify that the target string was not found. So you can write:The
>nulredirection makes sure thatfindwill not actually output any matching text, since that’s not what you want to do.