Go Premium for a chance to win a PS4. Enter to Win

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
?
398 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

824 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