Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having a batch file check its own output?

I'm wondering if it's possible to have a batch file check itself for a string.

I'm using a batch file to run Maven commands,and I want to check if anything failed by searching for a "FAILURE" string at the end of the script

I know you can FIND in other files, but can you have it check the current output on itself, or is the best solution to save the batch file output as a text and then search it?

As an example, if I had a batch file echo Hello World it would print Hello World, then I would want to search the output for Hello and tell me it found the string Hello.

like image 881
Hanna Avatar asked Dec 05 '22 14:12

Hanna


1 Answers

I like vane's idea to take action upon the return code provided by mvn, but instead of using ERRORLEVEL, I like to use the || operator. The commands after || are only excecuted if the prior command failed.

::initialize error flag to undefined
set "mvnErr="

::run your Maven command and define the error flag if there was an error
call mvn {your arguments here} || set mvnErr=1

::You can now take action if there was an error
if defined mvnErr echo there was a Maven error
like image 149
dbenham Avatar answered Dec 13 '22 13:12

dbenham