problem with for loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pavankumar.thati
Posts: 2
Joined: 12 Aug 2011 00:50

problem with for loop

#1 Post by pavankumar.thati » 12 Aug 2011 01:00

problem Description :
I need to get an output of active databases. For that i have writen the following code in suchaway that if the 4th line executes with out any error i'll echoed it as "Active" or "InActive".But in the following code for loop is executing once and skipping the rest of the iterations..
Please help me with this.


Code: Select all

@echo off
Setlocal EnableDelayedExpansion
For /F "tokens=*" %%a In ('mysql --user=%1 -p%2 -N -s -e "show databases"') do ( echo.skipped skipped
         mysql --user=%1 -p%2 --database=%%a -N -s -e "show tables">NUL 2>&1
         if ERRORLEVEL 1 (echo.%%a InActive ) else (echo.%%a Active)
         )


Output :

information_schema Active
skipped skipped
skipped skipped
skipped skipped

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

Re: problem with for loop

#2 Post by aGerman » 13 Aug 2011 06:52

Does your mysql request return an ERRORLEVEL value?

Regards
aGerman

pavankumar.thati
Posts: 2
Joined: 12 Aug 2011 00:50

Re: problem with for loop

#3 Post by pavankumar.thati » 16 Aug 2011 04:53

aGerman wrote:Does your mysql request return an ERRORLEVEL value?

Regards
aGerman

No Actually the ERRORLEVEL is set by DOS script not by mysql.Whenever mysql fails to run the The DOs script sets the ERRORLEVEL .....

Post Reply