Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-10-27
3
Medium Priority
?
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

722 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