2017-03-08 95 views
-1

我試圖儘可能減少這篇文章,而不遺漏信息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瀏覽器做了完整的或做了錯誤

+0

那麼您可以在腳本的頂部爲日誌文件名定義一個變量,但我沒有看到將任何輸出重定向到該日誌文件的單個實例。 – Squashman

+0

你的程序的第一行,你設置'echo on'。那麼你很驚訝,回聲在?如果你不想看到每個命令echo'd,請設置'echo off'。這並不奇怪。 – abelenky

+0

@abelenky歡呼的迴應。我並不感到驚訝。把它「關閉」只是輸出「回聲已關閉」進入日誌 – Nighthawkz

回答

4

改變

@echo on 

@echo off 

其中W生病關閉命令回顯。

正如你所說,TL; DR。然後,您可以選擇輸出到任意想要輸入的字符串,或者通過將>nul添加到不想要的行,並可能輸入2>nul來抑制錯誤消息,從而處理任何不需要的輸出。

+0

感謝您的回覆,我將與您一起玩 – Nighthawkz

+0

謝謝。我能夠使用這一點,只把我需要的一切 – Nighthawkz

相關問題