1

I have one batch job, let's say inventory.bat. This batch job will connect with application specific executable file and while connecting we will pass inputs to application executable based on inputs it will run the application process. Some times if no of records updated inside application is zero it will return warning message.

The executable code is not available and I want to re set the ERRORLEVEL to 0, if output is either warning or info in Batch output.

Batch code

..\\application.exe - update database - systemswitch:autoConvertFile="..\\sourcefilelocation\\filename.txt" 

output:

warning: no of updated records :0

some times

Info : no of updated records: 0 
Error: invalid data loaded
aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • 1
    So basically you want to check the output of the application whether none of the lines begin with `Info: ` or `Warning: ` and set the `ErrorLevel` to zero in case, correct? Do you want to set the `ErrorLevel` to non-zero otherwise? Perhaps this works for you: `application.exe ... | findstr /B /C:"Info: " /C:"Warning: " > nul` (or you want to pipe `inventory.bat`)... – aschipfl Sep 29 '17 at 12:19
  • 2
    See [Which cmd.exe internal commands clear the ERRORLEVEL to 0 upon success?](https://stackoverflow.com/questions/34968009/) and use any command which clears the errorlevel on success like `ver >nul`. – Mofi Sep 29 '17 at 12:23

1 Answers1

0

Another way to handle this is to save the ERRORLEVEL to a variable that you control. You can always know what will be returned.

SETLOCAL
SET "EXITCODE=0"

app.exe >"%TEMP%\app.log" 2>&1
SET "EXITCODE=%ERRORLEVEL%"
IF %EXITCODE% NEQ 0 (
    IF <output shows no real errors> (SET "EXITCODE=0")
)

EXIT /B %EXITCODE%
lit
  • 14,456
  • 10
  • 65
  • 119
  • What is the `` part? Do you mean a string comparison or something? –  Sep 29 '17 at 13:08
  • Check that. I will add something to capture stdout and stderr to a file. Determining if there are real errors means whatever needs to be done to check. String compare the logfile, detect existence of a file, etc... – lit Sep 29 '17 at 13:13
  • Oh I see. I think `FINDSTR` and `>` will be handy for you. –  Sep 29 '17 at 13:14