Board logo

标题: [文本处理] 批处理进度条显示 [打印本页]

作者: zhudonhua    时间: 2009-1-21 13:35     标题: 批处理进度条显示

问题背景:
   从sp.log依次中读取一条记录,然后去连接数据库,但是每次连接可能要花费20S的时间,考虑到可能会有上百次操作,因而需要有个进度提示信息。。
下面是我写的代码,帮忙看看哪里有问题???
/*读取sp.log中总共有多少行记录*/
  1. set /a m=1
  2. for /F "usebackq skip=2 tokens=1,2,3" %%i in ("%log%\sp.log") do  (
  3.     set /a m += 1
  4. )                  
  5. set count=1
  6. for /F "usebackq skip=2" %%i in ("%log%\sp.log") do  (
  7.     echo Backing up Store Procedure %%i                          >> "%log%\backup_all_sp_%db%_%srvname%_%year%%mon%%day%_%hour%%min%%ss%.log"                                         
  8.    sqlcmd -S%srvname% -d%db% -U%user% -P%password% -Q "select text from syscomments where id=object_id(%%i)" -o "%bak%\%srvname%_%db%_%%i_%year%%mon%%day%_%hour%%min%%ss%.PRC"
  9.     echo ... Finished:  %count%/%m% ...
  10.     set /a count += 1
  11. )
复制代码
问题:
    显示出来的不是预想中的结果
   
--------------------------------------
显示效果                     
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
... Finished: 1 / 20
作者: yslyxqysl    时间: 2009-1-21 13:52

  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. set /a m=1
  4. for /F "usebackq skip=2 tokens=1,2,3" %%i in ("%log%\sp.log") do  (
  5.     set /a m += 1
  6. )                  
  7. set count=1
  8. for /F "usebackq skip=2" %%i in ("%log%\sp.log") do  (
  9.     echo Backing up Store Procedure %%i                          >> "%log%\backup_all_sp_%db%_%srvname%_%year%%mon%%day%_%hour%%min%%ss%.log"                                         
  10.    sqlcmd -S%srvname% -d%db% -U%user% -P%password% -Q "select text from syscomments where id=object_id(%%i)" -o "%bak%\%srvname%_%db%_%%i_%year%%mon%%day%_%hour%%min%%ss%.PRC"
  11.     echo ... Finished:  !count!/%m% ...
  12.     set /a count += 1
  13. )
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2