Solved

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

Posted on 2014-10-27
3
376 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
Comment Utility
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
Comment Utility
Works great!!! Thank you soooo much!!!
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
No problem, glad it helped.

Steve
0

Featured Post

Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now