Search code examples
dos

cmd : getting results and if statement


Hi I am having problems with one of my first CMD scripts, any suggestions on how to go about this loop with grabbing the results outputted the command window with the if statements?

@echo off

:BEGIN

T:
cd js
cd ddf
cd invent


for %%s in ("invstk" "labmas") do ( 

Call Isutl -r %%s 


if result contains "%ISUTL=20: Cannot open index file" goto SendEmail else if the result = "Indexing Complete" continue to next file in 

list, if result not contains "%ISUTL=20: Cannot open index file" or "Indexing Complete" then call Isutl -r on that file again


)


:SendEmail


:DONESCAN
Exit

Solution

  • See if this does what you need:

    @echo off
    
    :BEGIN
    
    cd /d "t:\js\ddf\invent"
    for %%s in ("invstk" "labmas") do call :routine "%%s"
    del file.log 2>nul
    pause
    goto :EOF
    
    :routine
    Call Isutl -r "%~1" >file.log 2>&1
    find /i "ISUTL=20: Cannot open index file" <file.log >nul && goto SendEmail
    find /i "Indexing Complete" <file.log >nul && goto :EOF
    goto :routine
    
    :SendEmail
    rem send email
    goto :EOF