Check if command's output contains some text

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
guy
Posts: 1
Joined: 20 Jun 2010 06:49

Check if command's output contains some text

#1 Post by guy » 20 Jun 2010 06:58

I am trying to write a batch file that has to do the following:
1) run a command that has some output.
2) check if the output contains some text
3) if yes - do something

What I tryed to do is to save the output to a file and then save the data from file to variable:
[command] > c:\temp.txt
set /p RetVal= < c:\temp.txt
del temp.txt

But it doesn't work well.
Anybody has some ideas how to do all these?

Thanks a lot!

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Check if command's output contains some text

#2 Post by aGerman » 20 Jun 2010 07:22

You should tell us which command it is and if you try to process a Standard-Msg. or an Error-Msg.

Regards
aGerman

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: Check if command's output contains some text

#3 Post by avery_larry » 21 Jun 2010 10:09

Code: Select all

yourcommandhere | find /i "the text you're looking for"
if not errorlevel 1 (
   echo The stuff you want to do
   echo goes here
)

Javid
Posts: 1
Joined: 23 Feb 2017 01:52

Re: Check if command's output contains some text

#4 Post by Javid » 23 Feb 2017 01:56

avery_larry wrote:

Code: Select all

yourcommandhere | find /i "the text you're looking for"
if not errorlevel 1 (
   echo The stuff you want to do
   echo goes here
)


Thank you !! this works for me

Post Reply