Solved

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

Posted on 2014-10-27
3
384 Views
Last Modified: 2014-10-27
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.
0
Comment
Question by:tadeystas
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 40406815
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
0
 

Author Closing Comment

by:tadeystas
ID: 40406944
Works great!!! Thank you soooo much!!!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40406950
No problem, glad it helped.

Steve
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question