当前位置: 代码迷 >> vbScript >> bat脚本echo输出log大小限制的有关问题
  详细解决方案

bat脚本echo输出log大小限制的有关问题

热度:2167   发布时间:2013-02-26 00:00:00.0
bat脚本echo输出log大小限制的问题
bat脚本,使用如:
echo %%i -error>>error.log
这样的语句,有没有办法限制error.log的大小?比如限制在10MB,让它在总共5个log文件间循环写,满了写下一个这样的。

实在不行,可以让它只写一个文件,满了就把文件中过期的内容删了,写新的。

现在的情况是,我这个log写的比较频繁,经常几天就到几十兆了,得总清理,很麻烦。




------解决方案--------------------------------------------------------
你可以根据日期自动换日志文件,比如2009-8-20号一个文件2009-8-21号一个文件等等
------解决方案--------------------------------------------------------
BatchFile code
@echo off & setlocalcall :e abcd -errorpausegoto :eof:esetlocalset f=error1.log error2.log error3.log error4.log error5.logfor %%a in (%f%) do (    if not exist %%a cd.>%%a)set /a z=1024*1024*10set b=for %%a in (%f%) do (    if %%~za lss %z% set b=%%a&goto out):outif not defined b (    for %%a in (%f%) do (        more /e +1 %%a>tmp.log        move tmp.log %%a        set b=%%a&goto out2    )):out2>>%b% echo %*goto :eof
  相关解决方案