Batch file: check for line 5 in command output, if it says xxxx, then do yyyy

Title says it all.
I need to create batch file, which will call the command that has multiple line of output. I need to read line 5 and if it says xxxx, then proceed to yyyy, else proceed to zzzzz.



Try this. If you don't specifically need to go to yyyy and zzzz but just want to do something different then you can put it into the IF command between the ( and ) instead of the gotos.

@echo off
for /f "skip=5 delims=*" %%a in ('mycommand.exe -whatever etc') do (
set line=%%a
goto :next
):next
if "%line%"=="xxxxx" (
echo This is xxxxx"
goto yyyy
) ELSE (
echo It isn't xxxxx - it is %line%
goto zzzz
)

or if you want to check for it in the line somewhere you can use syntax like this:
if not "%line%"=="%line:xxxxx=FOUND%" (
echo xxxxx was found in the line: %line%
goto yyyy
) ELSE (
echo xxxxx was not found in the line: "%line%
goto zzzzz
)

Steve



Try this. If you don't specifically need to go to yyyy and zzzz but just want to do something different then you can put it into the IF command between the ( and ) instead of the gotos.

@echo off
for /f "skip=5 delims=*" %%a in ('mycommand.exe -whatever etc') do (
set line=%%a
goto :next
):next
if "%line%"=="xxxxx" (
echo This is xxxxx"
goto yyyy
) ELSE (
echo It isn't xxxxx - it is %line%
goto zzzz
)

or if you want to check for it in the line somewhere you can use syntax like this:
if not "%line%"=="%line:xxxxx=FOUND%" (
echo xxxxx was found in the line: %line%
goto yyyy
) ELSE (
echo xxxxx was not found in the line: "%line%
goto zzzzz
)

Steve



Works great!!! Thank you soooo much!!!



No problem, glad it helped.

Steve





Share this

Related Posts

There was an error in this gadget