IF statement with FIND

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mhinegardner
Posts: 1
Joined: 17 Mar 2010 11:50

IF statement with FIND

#1 Post by mhinegardner » 17 Mar 2010 11:58

I'm not sure the best way to go about doing this...

Ultimately I want to run a MySQL query and run that into a DOS FIND command...from that point, I want to be able to "do" something with the output. Perhaps with an IF statement.

This is what I had in mind:

SET MYSQLOUTPUT=mysql.exe -uroot -ppassword --execute="use db_name;select field from table;"
%MYSQLOUTPUT% | find "string"

After this point is where I'm stuck...

I'd like to be able do something like "IF this string is found...DO this...or goto another function"

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

Re: IF statement with FIND

#2 Post by aGerman » 17 Mar 2010 13:56

Should be something like this:

Code: Select all

for /f "delims=" %%a in ('mysql.exe -uroot -ppassword --execute^="use db_name^;select field from table^;"') do set "MYSQLOUTPUT=%%a"
echo %MYSQLOUTPUT%|find "string" >nul && (
  rem DO this
) || (
  rem goto another function
)

Post Reply