Page 1 of 1

Check if command's output contains some text

Posted: 20 Jun 2010 06:58
by guy
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!

Re: Check if command's output contains some text

Posted: 20 Jun 2010 07:22
by aGerman
You should tell us which command it is and if you try to process a Standard-Msg. or an Error-Msg.

Regards
aGerman

Re: Check if command's output contains some text

Posted: 21 Jun 2010 10:09
by avery_larry

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
)

Re: Check if command's output contains some text

Posted: 23 Feb 2017 01:56
by Javid
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