[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理进度条显示

问题背景:
   从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

  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. )
复制代码

TOP

返回列表