我试图尽可能地减少这篇文章而不遗漏信息TL; DR包括在底部。
我继承了一个简短的脚本
这里是说脚本
@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"
这尤其嘈杂,因为它进行了一些朱利安日期计算(我已经从我提出的脚本中删除了这些以减少已经存在的文本墙!)这最终会长达数千行。
正如你所看到的那样,它只是输出每一行,无论它是否成功完成,如果出现问题,使解释变得很痛苦。
我只希望日志显示是否部分/成功完成,和/或是否遇到错误(如上所示):
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批处理文件日志非常嘈杂,输出它所做的一切 - 希望减少它只输出有用信息,即它完成或错误(以及为什么!)
答案 0 :(得分:4)
变化
@echo on
到
@echo off
将关闭命令回显。
正如你所说,TL; DR。然后,您可以选择通过echo
任意字符串输出到屏幕,或者通过将>nul
附加到不想要的行并且可能2>nul
来抑制任何不需要的输出来处理错误消息。