我试图尽可能减少这篇文章,而不遗漏信息TL; DR包含在底部。如何停止将文件输出到日志文件的批处理文件?
我继承了一个脚本,在短
- 检查2个文件夹在服务器A上的图像和文本文件
- 副本服务器B
- 复制图像的文本文件到目标文件夹文件到图像的目标文件夹在服务器B
- 档案Server上运行这些文件
- 删除任何文件服务器A 超过5天的0
这里说的脚本
@echo on
set log=c:\temp\acsloadcopy.log
set txtsrc=C:\Users\LCI\Desktop\txtsrc
set imgsrc=C:\Users\LCI\Desktop\imgsrc
set txtdest=C:\Users\LCI\Desktop\txtdest
set imgdest=C:\Users\LCI\Desktop\imgdest
set txtbak=%txtsrc%\Archive
set imgbak=%imgsrc%\Archive
rem set txtautonomy=\\idolget\tm\%TM10Environment%\
if ("%tm10acis%"=="") (
call :stop 1 "No tmacis environment variable set - can't run"
)
if ("%tm10acis%"=="none") (
call :stop 0 "No Acs server for this environment (tmacis=none)"
)
set _hh=%time:~0,2%
if "%time:~0,1%"==" " set _hh=0%_hh:~1,1%
SET TIMESTAMP=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%-%_hh%-%TIME:~3,2%-%TIME:~6,2%
call :clean
call :dochecks
REM call :checkage %txtsrc%
REM COPY TO ACSE
xcopy %txtsrc%\*.* %txtdest%
if ERRORLEVEL 1 call :stop 1 "error copying %txtsrc% %txtdest%"
xcopy %imgsrc%\*.* %imgdest%
if ERRORLEVEL 1 call :stop 1 "error copying %imgsrc% %imgdest%"
REM to ARCHIVE
move /y %txtsrc%\*.* %txtbak%\%TIMESTAMP%
rem Xcopy %txtsrc%\*.* %txtbak%\%TIMESTAMP%
if ERRORLEVEL 1 call :stop 1 "error moving %txtsrc% %txtbak%\%TIMESTAMP%"
move /y %imgsrc%\*.* %imgbak%\%TIMESTAMP%
rem Xcopy %imgsrc%\*.* %imgbak%\%TIMESTAMP%
if ERRORLEVEL 1 call :stop 1 "error moving %imgsrc% %imgbak%\%TIMESTAMP%"
REM CLEAN UP OLD ARCHIVES
call :clean %txtbak%
call :clean %imgbak%
goto :eof
:dochecks
call :checkfolder %txtsrc%
call :checkfolder %imgsrc%
call :checkfolder %txtdest%
call :checkfolder %imgdest%
call :checkfolder %txtbak%
call :checkfolder %imgbak%
if not exist %txtbak%\%TIMESTAMP% mkdir %txtbak%\%TIMESTAMP%
if ERRORLEVEL 1 call :stop 1 "Can't create archive folder %txtbak%\%TIMESTAMP% "
if not exist %imgbak%\%TIMESTAMP% mkdir %imgbak%\%TIMESTAMP%
if ERRORLEVEL 1 call :stop 1 "Can't create archive folder %imgbak%\%TIMESTAMP% "
if exist %txtdest%\*.txt call :stop 1 "Previouly copied text files have not been processed by acs"
if exist %imgdest%\*.jpg call :stop 1 "Previouly copied image files have not been processed by acs"
if not exist %txtsrc%\*.txt call :stop 0 "No source text files"
if not exist %imgsrc%\*.jpg call :stop 0 "No source image files"
:skipcheck
goto :eof
:checkfolder
set f=%1
pushd %f%
if ERRORLEVEL 1 call :stop "folder %f% does not exist"
popd
goto :eof
:stop
set exitcode=%1
set exitmsg=%~2
echo %exitmsg%
exit %exitcode%
我的问题是,日志输出一切批处理文件在这里做的一些它的一个例子:
C:\Users\LCI\Desktop\testt>if ERRORLEVEL 1 call :stop 1 "error copying
C:\Users\LCI\Desktop\txtsrc C:\Users\LCI\Desktop\txtdest"
C:\Users\LCI\Desktop\testt>xcopy C:\Users\LCI\Desktop\imgsrc\*.* C:\Users\LCI\Desktop\imgdest
C:\Users\LCI\Desktop\imgsrc\dwqd.jpg
1 File(s) copied
C:\Users\LCI\Desktop\testt>if ERRORLEVEL 1 call :stop 1 "error copying C:\Users\LCI\Desktop\imgsrc C:\Users\LCI\Desktop\imgdest"
C:\Users\LCI\Desktop\testt>REM to ARCHIVE
C:\Users\LCI\Desktop\testt>move /y C:\Users\LCI\Desktop\txtsrc\*.* C:\Users\LCI\Desktop\txtsrc\Archive\2017-03-08-10-34-41
C:\Users\LCI\Desktop\txtsrc\awd.txt
C:\Users\LCI\Desktop\txtsrc\dwdw.txt
C:\Users\LCI\Desktop\txtsrc\wwqwq.txt
3 file(s) moved.
C:\Users\LCI\Desktop\testt>rem Xcopy C:\Users\LCI\Desktop\txtsrc\*.* C:\Users\LCI\Desktop\txtsrc\Archive\2017-03-08-10-34-41
C:\Users\LCI\Desktop\testt>if ERRORLEVEL 1 call :stop 1 "error moving C:\Users\LCI\Desktop\txtsrc C:\Users\LCI\Desktop\txtsrc\Archive\2017-03-08-10-34-41"
C:\Users\LCI\Desktop\testt>move /y C:\Users\LCI\Desktop\imgsrc\*.* C:\Users\LCI\Desktop\imgsrc\Archive\2017-03-08-10-34-41
C:\Users\LCI\Desktop\imgsrc\dwqd.jpg
1 file(s) moved.
C:\Users\LCI\Desktop\testt>rem Xcopy C:\Users\LCI\Desktop\imgsrc\*.* C:\Users\LCI\Desktop\imgsrc\Archive\2017-03-08-10-34-41
C:\Users\LCI\Desktop\testt>if ERRORLEVEL 1 call :stop 1 "error moving C:\Users\LCI\Desktop\imgsrc C:\Users\LCI\Desktop\imgsrc\Archive\2017-03-08-10-34-41"
C:\Users\LCI\Desktop\testt>REM to AUTONOMY
C:\Users\LCI\Desktop\testt>rem if ERRORLEVEL 1 call :stop 1 "error creating \2017-03-08-10-34-41"
这是作为特别吵它会进行一些Julian日期计算(我已经将这些内容从我构建的脚本中删除,以减少已经存在的文本内容!),最终的结果是数千行。
正如你所看到的,它只是输出每一行,因为它经历了,无论它是否成功完成,如果出现问题,解释会很痛苦。
只想日志显示,如果它部分完成/成功,和/或如果它遇到错误(如上面可以看出):
C:\Users\LCIAV\Desktop\txtsrc\awd.txt
C:\Users\LCIAV\Desktop\txtsrc\dwdw.txt
C:\Users\LCIAV\Desktop\txtsrc\wwqwq.txt
3 file(s) moved)
我试图增加一个输出管,只在脚本中使用的线(xcopy和IF的) - 这并没有改变,
我已经尝试通过另一个批处理文件调用该文件与过滤器管道末尾,这种工作,但是为了解释我想要的一切而变得头疼。
我在一赔,因为它为什么它的输出一切,如何解决它
我将不胜感激帮助理解为什么它的输出一切,如何解决它。
问候
TL; - (!为什么)DR批处理文件,日志是极其嘈杂,输出它所做的一切希望将其降低到输出有用的信息,只有IE浏览器做了完整的或做了错误
那么您可以在脚本的顶部为日志文件名定义一个变量,但我没有看到将任何输出重定向到该日志文件的单个实例。 – Squashman
你的程序的第一行,你设置'echo on'。那么你很惊讶,回声在?如果你不想看到每个命令echo'd,请设置'echo off'。这并不奇怪。 – abelenky
@abelenky欢呼的回应。我并不感到惊讶。把它“关闭”只是输出“回声已关闭”进入日志 – Nighthawkz