Solved

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

Posted on 2014-10-27
3
381 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

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 2008 Server C Drive too full 25 71
windows 10 versions 3 33
Change size 15 41
Reinstall Windows 10 3 14
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
An article on effective troubleshooting
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 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

15 Experts available now in Live!

Get 1:1 Help Now